Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add -t option for gmt time offset (normally MS-DOS filesyste...



details:   https://anonhg.NetBSD.org/src/rev/e736869c85a2
branches:  trunk
changeset: 551530:e736869c85a2
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Sep 07 22:09:11 2003 +0000

description:
add -t option for gmt time offset (normally MS-DOS filesystem has timestamp
in localtime, not GMT).  PR kern/22717

diffstat:

 sbin/mount_msdos/mount_msdos.8  |   8 +++++++-
 sbin/mount_msdos/mount_msdos.c  |  25 ++++++++++++++++++++-----
 sys/fs/msdosfs/denode.h         |  10 +++++-----
 sys/fs/msdosfs/direntry.h       |   7 ++++---
 sys/fs/msdosfs/msdosfs_conv.c   |  17 +++++++++--------
 sys/fs/msdosfs/msdosfs_vfsops.c |   5 +++--
 sys/fs/msdosfs/msdosfs_vnops.c  |  27 +++++++++++++++------------
 sys/fs/msdosfs/msdosfsmount.h   |   4 +++-
 8 files changed, 66 insertions(+), 37 deletions(-)

diffs (truncated from 360 to 300 lines):

diff -r dd3344ec6e2f -r e736869c85a2 sbin/mount_msdos/mount_msdos.8
--- a/sbin/mount_msdos/mount_msdos.8    Sun Sep 07 21:37:19 2003 +0000
+++ b/sbin/mount_msdos/mount_msdos.8    Sun Sep 07 22:09:11 2003 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: mount_msdos.8,v 1.27 2003/08/02 11:43:21 jdolecek Exp $
+.\" $NetBSD: mount_msdos.8,v 1.28 2003/09/07 22:09:11 itojun Exp $
 .\"
 .\" Copyright (c) 1993, 1994 Christopher G. Demetriou
 .\" All rights reserved.
@@ -45,6 +45,7 @@
 .Op Fl g Ar gid
 .Op Fl m Ar mask
 .Op Fl M Ar mask
+.Op Fl t Ar gmtoff
 .Op Fl s
 .Op Fl l
 .Op Fl 9
@@ -113,6 +114,11 @@
 is used if it is supplied and
 .Fl M
 is omitted. See description of previous option for details.
+.It Fl t Ar gmtoff
+Set the time zone offset (in seconds) from UTC to
+.Ar gmtoff ,
+with positive values indicating east of the Prime Meridian.
+If not set, the user's current time zone will be used.
 .It Fl s
 Force behaviour to
 ignore and not generate Win'95 long filenames.
diff -r dd3344ec6e2f -r e736869c85a2 sbin/mount_msdos/mount_msdos.c
--- a/sbin/mount_msdos/mount_msdos.c    Sun Sep 07 21:37:19 2003 +0000
+++ b/sbin/mount_msdos/mount_msdos.c    Sun Sep 07 22:09:11 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_msdos.c,v 1.30 2003/08/02 11:42:20 jdolecek Exp $ */
+/* $NetBSD: mount_msdos.c,v 1.31 2003/09/07 22:09:11 itojun Exp $ */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mount_msdos.c,v 1.30 2003/08/02 11:42:20 jdolecek Exp $");
+__RCSID("$NetBSD: mount_msdos.c,v 1.31 2003/09/07 22:09:11 itojun Exp $");
 #endif /* not lint */
 
 #include <sys/cdefs.h>
@@ -51,6 +51,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 #include <util.h>
 
@@ -87,13 +88,15 @@
 {
        struct msdosfs_args args;
        struct stat sb;
-       int c, mntflags, set_gid, set_uid, set_mask, set_dirmask;
+       int c, mntflags, set_gid, set_uid, set_mask, set_dirmask, set_gmtoff;
        char *dev, *dir, ndir[MAXPATHLEN+1];
+       time_t now;
+       struct tm *tm;
 
-       mntflags = set_gid = set_uid = set_mask = set_dirmask = 0;
+       mntflags = set_gid = set_uid = set_mask = set_dirmask = set_gmtoff = 0;
        (void)memset(&args, '\0', sizeof(args));
 
-       while ((c = getopt(argc, argv, "Gsl9u:g:m:M:o:")) != -1) {
+       while ((c = getopt(argc, argv, "Gsl9u:g:m:M:o:t:")) != -1) {
                switch (c) {
                case 'G':
                        args.flags |= MSDOSFSMNT_GEMDOSFS;
@@ -126,6 +129,10 @@
                case 'o':
                        getmntopts(optarg, mopts, &mntflags, 0);
                        break;
+               case 't':
+                       args.gmtoff = atoi(optarg);
+                       set_gmtoff = 1;
+                       break;
                case '?':
                default:
                        usage();
@@ -175,6 +182,14 @@
                                sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
                }
        }
+
+       if (!set_gmtoff) {
+               /* use user's time zone as default */
+               time(&now);
+               tm = localtime(&now);
+               args.gmtoff = tm->tm_gmtoff;
+
+       }
        args.flags |= MSDOSFSMNT_VERSIONED;
        args.version = MSDOSFSMNT_VERSION;
 
diff -r dd3344ec6e2f -r e736869c85a2 sys/fs/msdosfs/denode.h
--- a/sys/fs/msdosfs/denode.h   Sun Sep 07 21:37:19 2003 +0000
+++ b/sys/fs/msdosfs/denode.h   Sun Sep 07 22:09:11 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: denode.h,v 1.3 2003/06/29 22:31:09 fvdl Exp $  */
+/*     $NetBSD: denode.h,v 1.4 2003/09/07 22:09:11 itojun Exp $        */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -221,18 +221,18 @@
 #define        VTODE(vp)       ((struct denode *)(vp)->v_data)
 #define        DETOV(de)       ((de)->de_vnode)
 
-#define        DETIMES(dep, acc, mod, cre) \
+#define        DETIMES(dep, acc, mod, cre, gmtoff) \
        if ((dep)->de_flag & (DE_UPDATE | DE_CREATE | DE_ACCESS)) { \
                (dep)->de_flag |= DE_MODIFIED; \
                if ((dep)->de_flag & DE_UPDATE) { \
-                       unix2dostime((mod), &(dep)->de_MDate, &(dep)->de_MTime, NULL); \
+                       unix2dostime((mod), gmtoff, &(dep)->de_MDate, &(dep)->de_MTime, NULL); \
                        (dep)->de_Attributes |= ATTR_ARCHIVE; \
                } \
                if (!((dep)->de_pmp->pm_flags & MSDOSFSMNT_NOWIN95)) { \
                        if ((dep)->de_flag & DE_ACCESS) \
-                               unix2dostime((acc), &(dep)->de_ADate, NULL, NULL); \
+                               unix2dostime((acc), gmtoff, &(dep)->de_ADate, NULL, NULL); \
                        if ((dep)->de_flag & DE_CREATE) \
-                               unix2dostime((cre), &(dep)->de_CDate, &(dep)->de_CTime, &(dep)->de_CHun); \
+                               unix2dostime((cre), gmtoff, &(dep)->de_CDate, &(dep)->de_CTime, &(dep)->de_CHun); \
                } \
                (dep)->de_flag &= ~(DE_UPDATE | DE_CREATE | DE_ACCESS); \
        }
diff -r dd3344ec6e2f -r e736869c85a2 sys/fs/msdosfs/direntry.h
--- a/sys/fs/msdosfs/direntry.h Sun Sep 07 21:37:19 2003 +0000
+++ b/sys/fs/msdosfs/direntry.h Sun Sep 07 22:09:11 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: direntry.h,v 1.1 2002/12/26 12:31:33 jdolecek Exp $    */
+/*     $NetBSD: direntry.h,v 1.2 2003/09/07 22:09:11 itojun Exp $      */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -119,9 +119,10 @@
 #define DD_YEAR_SHIFT          9
 
 #ifdef _KERNEL
-void   unix2dostime __P((struct timespec *tsp, u_int16_t *ddp,
+void   unix2dostime __P((struct timespec *tsp, int gmtoff, u_int16_t *ddp,
            u_int16_t *dtp, u_int8_t *dhp));
-void   dos2unixtime __P((u_int dd, u_int dt, u_int dh, struct timespec *tsp));
+void   dos2unixtime __P((u_int dd, u_int dt, u_int dh, int gmtoff,
+           struct timespec *tsp));
 int    dos2unixfn __P((u_char dn[11], u_char *un, int lower));
 int    unix2dosfn __P((const u_char *un, u_char dn[12], int unlen,
            u_int gen));
diff -r dd3344ec6e2f -r e736869c85a2 sys/fs/msdosfs/msdosfs_conv.c
--- a/sys/fs/msdosfs/msdosfs_conv.c     Sun Sep 07 21:37:19 2003 +0000
+++ b/sys/fs/msdosfs/msdosfs_conv.c     Sun Sep 07 22:09:11 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_conv.c,v 1.1 2002/12/26 12:31:34 jdolecek Exp $        */
+/*     $NetBSD: msdosfs_conv.c,v 1.2 2003/09/07 22:09:11 itojun Exp $  */
 
 /*-
  * Copyright (C) 1995, 1997 Wolfgang Solfrank.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_conv.c,v 1.1 2002/12/26 12:31:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_conv.c,v 1.2 2003/09/07 22:09:11 itojun Exp $");
 
 /*
  * System include files.
@@ -96,8 +96,9 @@
  * file timestamps. The passed in unix time is assumed to be in GMT.
  */
 void
-unix2dostime(tsp, ddp, dtp, dhp)
+unix2dostime(tsp, gmtoff, ddp, dtp, dhp)
        struct timespec *tsp;
+       int gmtoff;
        u_int16_t *ddp;
        u_int16_t *dtp;
        u_int8_t *dhp;
@@ -113,8 +114,7 @@
         * 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 - (rtc_offset * 60)
-            /* +- daylight savings time correction */ ;
+       t = tsp->tv_sec + gmtoff; /* time zone correction */
        t &= ~1;
        if (lasttime != t) {
                lasttime = t;
@@ -177,10 +177,11 @@
  * not be too efficient.
  */
 void
-dos2unixtime(dd, dt, dh, tsp)
+dos2unixtime(dd, dt, dh, gmtoff, tsp)
        u_int dd;
        u_int dt;
        u_int dh;
+       int gmtoff;
        struct timespec *tsp;
 {
        u_long seconds;
@@ -227,8 +228,8 @@
                days += ((dd & DD_DAY_MASK) >> DD_DAY_SHIFT) - 1;
                lastseconds = (days * 24 * 60 * 60) + SECONDSTO1980;
        }
-       tsp->tv_sec = seconds + lastseconds + (rtc_offset * 60)
-            /* -+ daylight savings time correction */ ;
+       tsp->tv_sec = seconds + lastseconds;
+       tsp->tv_sec -= gmtoff;  /* time zone correction */
        tsp->tv_nsec = (dh % 100) * 10000000;
 }
 
diff -r dd3344ec6e2f -r e736869c85a2 sys/fs/msdosfs/msdosfs_vfsops.c
--- a/sys/fs/msdosfs/msdosfs_vfsops.c   Sun Sep 07 21:37:19 2003 +0000
+++ b/sys/fs/msdosfs/msdosfs_vfsops.c   Sun Sep 07 22:09:11 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_vfsops.c,v 1.8 2003/08/02 11:41:21 jdolecek Exp $      */
+/*     $NetBSD: msdosfs_vfsops.c,v 1.9 2003/09/07 22:09:11 itojun Exp $        */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.8 2003/08/02 11:41:21 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.9 2003/09/07 22:09:11 itojun Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -147,6 +147,7 @@
        pmp->pm_uid = argp->uid;
        pmp->pm_mask = argp->mask & ALLPERMS;
        pmp->pm_dirmask = argp->dirmask & ALLPERMS;
+       pmp->pm_gmtoff = argp->gmtoff;
        pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT;
 
        /*
diff -r dd3344ec6e2f -r e736869c85a2 sys/fs/msdosfs/msdosfs_vnops.c
--- a/sys/fs/msdosfs/msdosfs_vnops.c    Sun Sep 07 21:37:19 2003 +0000
+++ b/sys/fs/msdosfs/msdosfs_vnops.c    Sun Sep 07 22:09:11 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_vnops.c,v 1.6 2003/08/02 11:41:21 jdolecek Exp $       */
+/*     $NetBSD: msdosfs_vnops.c,v 1.7 2003/09/07 22:09:11 itojun Exp $ */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.6 2003/08/02 11:41:21 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.7 2003/09/07 22:09:11 itojun Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -156,7 +156,7 @@
        ndirent.de_pmp = pdep->de_pmp;
        ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
        TIMEVAL_TO_TIMESPEC(&time, &ts);
-       DETIMES(&ndirent, &ts, &ts, &ts);
+       DETIMES(&ndirent, &ts, &ts, &ts, pdep->de_pmp->pm_gmtoff);
        if ((error = createde(&ndirent, pdep, &dep, cnp)) != 0)
                goto bad;
        if ((cnp->cn_flags & SAVESTART) == 0)
@@ -221,7 +221,7 @@
        simple_lock(&vp->v_interlock);
        if (vp->v_usecount > 1) {
                TIMEVAL_TO_TIMESPEC(&time, &ts);
-               DETIMES(dep, &ts, &ts, &ts);
+               DETIMES(dep, &ts, &ts, &ts, dep->de_pmp->pm_gmtoff);
        }
        simple_unlock(&vp->v_interlock);
        return (0);
@@ -287,7 +287,7 @@
        u_long fileid;
 
        TIMEVAL_TO_TIMESPEC(&time, &ts);
-       DETIMES(dep, &ts, &ts, &ts);
+       DETIMES(dep, &ts, &ts, &ts, pmp->pm_gmtoff);
        vap->va_fsid = dep->de_dev;
        /*
         * The following computation of the fileid must be the same as that
@@ -316,10 +316,13 @@
        vap->va_nlink = 1;
        vap->va_rdev = 0;
        vap->va_size = ap->a_vp->v_size;
-       dos2unixtime(dep->de_MDate, dep->de_MTime, 0, &vap->va_mtime);
+       dos2unixtime(dep->de_MDate, dep->de_MTime, 0, pmp->pm_gmtoff,
+           &vap->va_mtime);
        if (dep->de_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);
+               dos2unixtime(dep->de_ADate, 0, 0, pmp->pm_gmtoff,
+                   &vap->va_atime);



Home | Main Index | Thread Index | Old Index