/*
* Copyright (c) 2000-2001, Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: smbfs_subr.c,v 1.18 2005/02/02 00:22:23 lindak Exp $
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* From BSD/Darwin smbfs_subr.c
*/
#include <netsmb/smb_osdep.h>
#include <netsmb/smb_conn.h>
#include <netsmb/smb_subr.h>
/*
* Time & date conversion routines taken from msdosfs. Although leap
* year calculation is bogus, it's sufficient before 2100 :)
*/
/*
* This is the format of the contents of the deTime field in the direntry
* structure.
* We don't use bitfields because we don't know how compilers for
* arbitrary machines will lay them out.
*/
#define DT_2SECONDS_SHIFT 0
/*
* This is the format of the contents of the deDate field in the direntry
* structure.
*/
#define DD_DAY_SHIFT 0
/*
* Total number of days that have passed for each month in a regular year.
*/
31, 59, 90, 120, 151, 181,
212, 243, 273, 304, 334, 365
};
/*
* Total number of days that have passed for each month in a leap year.
*/
31, 60, 91, 121, 152, 182,
213, 244, 274, 305, 335, 366
};
/*
* Variables used to remember parts of the last time conversion. Maybe we
* can avoid a full conversion.
*/
/* Lock for the lastxxx variables */
/*
* Number of seconds between 1970 and 1601 year
* (134774 days)
*/
/*
* Convert NT time (tenths of microseconds since 1601)
* to Unix seconds+nanoseconds since 1970. Any time
* earlier than 1970 is converted to Unix time zero.
* Both are GMT-based (no time zone adjustments).
*/
void
{
/* Optimize time zero. */
if (nt_time == 0) {
return;
}
if (nt_sec <= DIFF1970TO1601) {
return;
}
}
/*
* Convert Unix time (seconds+nanoseconds since 1970)
* to NT time (tenths of microseconds since 1601).
* Exception: Convert time zero (really any time in
* the first second of 1970) to NT time zero.
* Both are GMT-based (no time zone adjustments).
*/
void
{
*nt_time = 0;
return;
}
}
/*
* Time zone conversion stuff, only used in old dialects.
* Don't adjust time zero for either conversion.
*/
void
{
*seconds = 0;
else
}
void
{
if (seconds == 0)
else
}
/*
*/
void
{
long t;
/*
* If the time from the last conversion is the same as now, then
* skip the computations and use the saved result.
*/
t &= ~1;
if (lasttime != t) {
lasttime = t;
if (t < 0) {
/*
* This is before 1970, so it's before 1980,
* and can't be represented as a DOS time.
* Just represent it as the DOS epoch.
*/
lastdtime = 0;
+ (1 << DD_MONTH_SHIFT)
} else {
/*
* If the number of days since 1970 is the same as
* the last time we did the computation then skip
* all this leap year and month stuff.
*/
/*
* XXX - works in 2000, but won't
* work in 2100.
*/
break;
}
/*
* XXX - works in 2000, but won't work in 2100.
*/
;
if (month > 0)
/*
* Remember DOS's idea of time is relative
* to 1980, but UN*X's is relative to 1970.
* If somehow we get a time before 1980 then
* don't give totally crazy results.
*/
if (year > 1980)
}
}
}
if (dhp)
}
/*
* The number of seconds between Jan 1, 1970 and Jan 1, 1980. In that
* interval there were 8 regular years and 2 leap years.
*/
void
{
if (dd == 0) {
return;
}
+ dh / 100;
/*
* If the year, month, and day from the last conversion are the
* same then use the saved value.
*/
if (lastdosdate != dd) {
days = 0;
/*
* XXX - works in 2000, but won't work in 2100.
*/
if ((year & 0x03) == 0)
days--; /* if year is a leap year */
month = 1;
}
if (month > 1)
}
}
void
smb_time_init(void)
{
}
void
smb_time_fini(void)
{
}