1: /* 2: * SCCS id @(#)rc.c 2.1 (Berkeley) 8/5/83 3: */ 4: 5: #include "rc.h" 6: #if NRC > 0 7: #include "param.h" 8: #include <sys/dir.h> 9: #include <sys/user.h> 10: #include <sys/conf.h> 11: #include <sys/seg.h> 12: #include <sys/time.h> 13: #include <sys/rcreg.h> 14: 15: extern struct rcdevice *RCADDR; 16: 17: rcread(dev) 18: dev_t dev; 19: { 20: struct tm t; 21: 22: if(u.u_count != sizeof(t)) { 23: u.u_error = EINVAL; 24: return; 25: } 26: t.tm_year = (((RCADDR->rcymd) >> 9) & 0177); 27: t.tm_mon = (((RCADDR->rcymd) >> 5) & 017); 28: t.tm_mday = ((RCADDR->rcymd) & 037); 29: t.tm_hour = (((RCADDR->rchm) >> 8) & 037); 30: t.tm_min = ((RCADDR->rchm) & 077); 31: t.tm_sec = ((RCADDR->rcsec) & 077); 32: t.tm_wday = -1; 33: t.tm_yday = -1; 34: t.tm_isdst = -1; 35: 36: if (copyout((caddr_t) &t, (caddr_t) u.u_base, sizeof t) < 0) 37: u.u_error = EFAULT; 38: u.u_count -= sizeof t; 39: } 40: 41: rcwrite(dev) 42: dev_t dev; 43: { 44: register ymd; 45: register hm; 46: struct tm t; 47: 48: 49: if(u.u_count != sizeof(t)) { 50: u.u_error = EINVAL; 51: return; 52: } 53: if (copyin((caddr_t) u.u_base, (caddr_t) &t, sizeof(t)) < 0) { 54: u.u_error = EINVAL; 55: return; 56: } 57: if (suser()) { 58: if((t.tm_year < 0) || (t.tm_year > 99) || 59: (t.tm_mon < 1) || (t.tm_mon > 12) || 60: (t.tm_mday < 1) || (t.tm_mday > 31) || 61: (t.tm_hour < 0) || (t.tm_hour > 23) || 62: (t.tm_min < 0) || (t.tm_min > 59)) 63: { 64: u.u_error = EINVAL; 65: return; 66: } 67: ymd = ((((t.tm_year) << 4) | t.tm_mon) << 5) | t.tm_mday; 68: hm = (t.tm_hour << 8) | t.tm_min; 69: 70: do { /*set rcymd field*/ 71: RCADDR->rcymd = ymd; 72: while (RCADDR->rcymd != ymd) 73: ; 74: RCADDR->rcsec = ymd; 75: } while (RCADDR->rcymd != ymd); 76: 77: do { /*set rthm field*/ 78: RCADDR->rchm = hm; 79: while (RCADDR->rchm != hm) 80: ; 81: RCADDR->rcsec = hm; 82: } while (RCADDR->rchm != hm); 83: } 84: } 85: #endif NRC