aboutsummaryrefslogtreecommitdiff
path: root/sys/fs
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2006-10-24 11:14:05 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2006-10-24 11:14:05 +0000
commit3c960d93796e0af90139477c4f85128a384edc43 (patch)
tree5426603e455e28b39b7507678ac90f92a4ed2c0f /sys/fs
parent7ea93e912bf0ef51cec2ce4e86557eef4039ce57 (diff)
downloadsrc-3c960d93796e0af90139477c4f85128a384edc43.tar.gz
src-3c960d93796e0af90139477c4f85128a384edc43.zip
Replace slightly crummy fattime<->timespec conversion functions.
Notes
Notes: svn path=/head/; revision=163647
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/msdosfs/denode.h10
-rw-r--r--sys/fs/msdosfs/direntry.h3
-rw-r--r--sys/fs/msdosfs/msdosfs_conv.c164
-rw-r--r--sys/fs/msdosfs/msdosfs_denode.c3
-rw-r--r--sys/fs/msdosfs/msdosfs_vnops.c16
5 files changed, 16 insertions, 180 deletions
diff --git a/sys/fs/msdosfs/denode.h b/sys/fs/msdosfs/denode.h
index d77d8e121f3b..4fa51aae4fe3 100644
--- a/sys/fs/msdosfs/denode.h
+++ b/sys/fs/msdosfs/denode.h
@@ -218,8 +218,8 @@ struct denode {
#define DETIMES(dep, acc, mod, cre) do { \
if ((dep)->de_flag & DE_UPDATE) { \
(dep)->de_flag |= DE_MODIFIED; \
- unix2dostime((mod), &(dep)->de_MDate, &(dep)->de_MTime, \
- NULL); \
+ timespec2fattime((mod), 0, &(dep)->de_MDate, \
+ &(dep)->de_MTime, NULL); \
(dep)->de_Attributes |= ATTR_ARCHIVE; \
} \
if ((dep)->de_pmp->pm_flags & MSDOSFSMNT_NOWIN95) { \
@@ -229,15 +229,15 @@ struct denode {
if ((dep)->de_flag & DE_ACCESS) { \
u_int16_t adate; \
\
- unix2dostime((acc), &adate, NULL, NULL); \
+ timespec2fattime((acc), 0, &adate, NULL, NULL); \
if (adate != (dep)->de_ADate) { \
(dep)->de_flag |= DE_MODIFIED; \
(dep)->de_ADate = adate; \
} \
} \
if ((dep)->de_flag & DE_CREATE) { \
- unix2dostime((cre), &(dep)->de_CDate, &(dep)->de_CTime, \
- &(dep)->de_CHun); \
+ timespec2fattime((cre), 0, &(dep)->de_CDate, \
+ &(dep)->de_CTime, &(dep)->de_CHun); \
(dep)->de_flag |= DE_MODIFIED; \
} \
(dep)->de_flag &= ~(DE_UPDATE | DE_CREATE | DE_ACCESS); \
diff --git a/sys/fs/msdosfs/direntry.h b/sys/fs/msdosfs/direntry.h
index 7e325f77647d..6b5f82d67b1a 100644
--- a/sys/fs/msdosfs/direntry.h
+++ b/sys/fs/msdosfs/direntry.h
@@ -139,9 +139,6 @@ struct msdosfsmount;
char *mbnambuf_flush(struct dirent *dp);
void mbnambuf_init(void);
void mbnambuf_write(char *name, int id);
-void unix2dostime(struct timespec *tsp, u_int16_t *ddp,
- u_int16_t *dtp, u_int8_t *dhp);
-void dos2unixtime(u_int dd, u_int dt, u_int dh, struct timespec *tsp);
int dos2unixfn(u_char dn[11], u_char *un, int lower,
struct msdosfsmount *pmp);
int unix2dosfn(const u_char *un, u_char dn[12], size_t unlen, u_int gen,
diff --git a/sys/fs/msdosfs/msdosfs_conv.c b/sys/fs/msdosfs/msdosfs_conv.c
index c9dee480a90a..bde92fd9b827 100644
--- a/sys/fs/msdosfs/msdosfs_conv.c
+++ b/sys/fs/msdosfs/msdosfs_conv.c
@@ -55,7 +55,6 @@
#include <sys/clock.h>
#include <sys/kernel.h> /* defines tz */
#include <sys/systm.h>
-#include <sys/clock.h>
#include <sys/dirent.h>
#include <sys/iconv.h>
#include <sys/mount.h>
@@ -70,31 +69,6 @@ extern struct iconv_functions *msdosfs_iconv;
#include <fs/msdosfs/msdosfsmount.h>
#include <fs/msdosfs/direntry.h>
-/*
- * Total number of days that have passed for each month in a regular year.
- */
-static u_short regyear[] = {
- 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.
- */
-static u_short leapyear[] = {
- 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.
- */
-static u_long lasttime;
-static u_long lastday;
-static u_short lastddate;
-static u_short lastdtime;
-
static int mbsadjpos(const char **, size_t, size_t, int, int, void *handle);
static u_int16_t dos2unixchr(const u_char **, size_t *, int, struct msdosfsmount *);
static u_int16_t unix2doschr(const u_char **, size_t *, struct msdosfsmount *);
@@ -106,144 +80,6 @@ static size_t nambuf_len;
static int nambuf_last_id;
/*
- * Convert the unix version of time to dos's idea of time to be used in
- * file timestamps. The passed in unix time is assumed to be in GMT.
- */
-void
-unix2dostime(tsp, ddp, dtp, dhp)
- struct timespec *tsp;
- u_int16_t *ddp;
- u_int16_t *dtp;
- u_int8_t *dhp;
-{
- u_long t;
- u_long days;
- u_long inc;
- u_long year;
- u_long month;
- u_short *months;
-
- /*
- * If the time from the last conversion is the same as now, then
- * skip the computations and use the saved result.
- */
- t = tsp->tv_sec - utc_offset();
- /* - daylight savings time correction */
- t &= ~1;
- if (lasttime != t) {
- lasttime = t;
- lastdtime = (((t / 2) % 30) << DT_2SECONDS_SHIFT)
- + (((t / 60) % 60) << DT_MINUTES_SHIFT)
- + (((t / 3600) % 24) << DT_HOURS_SHIFT);
-
- /*
- * 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.
- */
- days = t / (24 * 60 * 60);
- if (days != lastday) {
- lastday = days;
- for (year = 1970;; year++) {
- inc = year & 0x03 ? 365 : 366;
- if (days < inc)
- break;
- days -= inc;
- }
- months = year & 0x03 ? regyear : leapyear;
- for (month = 0; days >= months[month]; month++)
- ;
- if (month > 0)
- days -= months[month - 1];
- lastddate = ((days + 1) << DD_DAY_SHIFT)
- + ((month + 1) << DD_MONTH_SHIFT);
- /*
- * Remember dos's idea of time is relative to 1980.
- * unix's is relative to 1970. If somehow we get a
- * time before 1980 then don't give totally crazy
- * results.
- */
- if (year > 1980)
- lastddate += (year - 1980) << DD_YEAR_SHIFT;
- }
- }
- if (dtp)
- *dtp = lastdtime;
- if (dhp)
- *dhp = (tsp->tv_sec & 1) * 100 + tsp->tv_nsec / 10000000;
-
- *ddp = lastddate;
-}
-
-/*
- * The number of seconds between Jan 1, 1970 and Jan 1, 1980. In that
- * interval there were 8 regular years and 2 leap years.
- */
-#define SECONDSTO1980 (((8 * 365) + (2 * 366)) * (24 * 60 * 60))
-
-static u_short lastdosdate;
-static u_long lastseconds;
-
-/*
- * Convert from dos' idea of time to unix'. This will probably only be
- * called from the stat(), and fstat() system calls and so probably need
- * not be too efficient.
- */
-void
-dos2unixtime(dd, dt, dh, tsp)
- u_int dd;
- u_int dt;
- u_int dh;
- struct timespec *tsp;
-{
- u_long seconds;
- u_long month;
- u_long year;
- u_long days;
- u_short *months;
-
- if (dd == 0) {
- /*
- * Uninitialized field, return the epoch.
- */
- tsp->tv_sec = 0;
- tsp->tv_nsec = 0;
- return;
- }
- seconds = (((dt & DT_2SECONDS_MASK) >> DT_2SECONDS_SHIFT) << 1)
- + ((dt & DT_MINUTES_MASK) >> DT_MINUTES_SHIFT) * 60
- + ((dt & DT_HOURS_MASK) >> DT_HOURS_SHIFT) * 3600
- + dh / 100;
- /*
- * If the year, month, and day from the last conversion are the
- * same then use the saved value.
- */
- if (lastdosdate != dd) {
- lastdosdate = dd;
- days = 0;
- year = (dd & DD_YEAR_MASK) >> DD_YEAR_SHIFT;
- days = year * 365;
- days += year / 4 + 1; /* add in leap days */
- if ((year & 0x03) == 0)
- days--; /* if year is a leap year */
- months = year & 0x03 ? regyear : leapyear;
- month = (dd & DD_MONTH_MASK) >> DD_MONTH_SHIFT;
- if (month < 1 || month > 12) {
- printf("dos2unixtime(): month value out of range (%ld)\n",
- month);
- month = 1;
- }
- if (month > 1)
- days += months[month - 2];
- days += ((dd & DD_DAY_MASK) >> DD_DAY_SHIFT) - 1;
- lastseconds = (days * 24 * 60 * 60) + SECONDSTO1980;
- }
- tsp->tv_sec = seconds + lastseconds + utc_offset();
- /* + daylight savings time correction */
- tsp->tv_nsec = (dh % 100) * 10000000;
-}
-
-/*
* 0 - character disallowed in long file name.
* 1 - character should be replaced by '_' in DOS file name,
* and generation number inserted.
diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c
index e2dbc9b623cf..726f7a0630cf 100644
--- a/sys/fs/msdosfs/msdosfs_denode.c
+++ b/sys/fs/msdosfs/msdosfs_denode.c
@@ -55,6 +55,7 @@
#include <sys/malloc.h>
#include <sys/bio.h>
#include <sys/buf.h>
+#include <sys/clock.h>
#include <sys/vnode.h>
#include <sys/mutex.h>
@@ -210,7 +211,7 @@ deget(pmp, dirclust, diroffset, depp)
ldep->de_FileSize = pmp->pm_rootdirsize * DEV_BSIZE;
}
/*
- * fill in time and date so that dos2unixtime() doesn't
+ * fill in time and date so that fattime2timespec() doesn't
* spit up when called from msdosfs_getattr() with root
* denode
*/
diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c
index abf4e8a5b9ef..e7a64e7132fb 100644
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -57,6 +57,7 @@
#include <sys/stat.h>
#include <sys/bio.h>
#include <sys/conf.h>
+#include <sys/clock.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/mount.h>
@@ -340,10 +341,11 @@ msdosfs_getattr(ap)
vap->va_nlink = 1;
vap->va_rdev = 0;
vap->va_size = dep->de_FileSize;
- dos2unixtime(dep->de_MDate, dep->de_MTime, 0, &vap->va_mtime);
+ fattime2timespec(dep->de_MDate, dep->de_MTime, 0, 0, &vap->va_mtime);
if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
- dos2unixtime(dep->de_ADate, 0, 0, &vap->va_atime);
- dos2unixtime(dep->de_CDate, dep->de_CTime, dep->de_CHun, &vap->va_ctime);
+ fattime2timespec(dep->de_ADate, 0, 0, 0, &vap->va_atime);
+ fattime2timespec(dep->de_CDate, dep->de_CTime, dep->de_CHun,
+ 0, &vap->va_ctime);
} else {
vap->va_atime = vap->va_mtime;
vap->va_ctime = vap->va_mtime;
@@ -484,13 +486,13 @@ msdosfs_setattr(ap)
if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
vap->va_atime.tv_sec != VNOVAL) {
dep->de_flag &= ~DE_ACCESS;
- unix2dostime(&vap->va_atime, &dep->de_ADate,
- NULL, NULL);
+ timespec2fattime(&vap->va_atime, 0,
+ &dep->de_ADate, NULL, NULL);
}
if (vap->va_mtime.tv_sec != VNOVAL) {
dep->de_flag &= ~DE_UPDATE;
- unix2dostime(&vap->va_mtime, &dep->de_MDate,
- &dep->de_MTime, NULL);
+ timespec2fattime(&vap->va_mtime, 0,
+ &dep->de_MDate, &dep->de_MTime, NULL);
}
dep->de_Attributes |= ATTR_ARCHIVE;
dep->de_flag |= DE_MODIFIED;