Print this page
NEX-14666 Need to provide SMB 2.1 Client
NEX-17187 panic in smbfs_acl_store
NEX-17231 smbfs create xattr files finds wrong file
NEX-17224 smbfs lookup EINVAL should be ENOENT
NEX-17260 SMB1 client fails to list directory after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
and: (cleanup)

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/smbclnt/netsmb/smb_time.c
          +++ new/usr/src/uts/common/fs/smbclnt/netsmb/smb_time.c
↓ open down ↓ 27 lines elided ↑ open up ↑
  28   28   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29   29   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30   30   * SUCH DAMAGE.
  31   31   *
  32   32   * $Id: smbfs_subr.c,v 1.18 2005/02/02 00:22:23 lindak Exp $
  33   33   */
  34   34  
  35   35  /*
  36   36   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  37   37   * Use is subject to license terms.
       38 + *
       39 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  38   40   */
  39   41  
  40   42  /*
  41   43   * Time conversion functions (to/from DOS, NT times)
  42   44   * From BSD/Darwin smbfs_subr.c
  43   45   */
  44   46  
  45   47  #include <sys/param.h>
  46   48  #include <sys/systm.h>
  47   49  #include <sys/time.h>
  48   50  #include <sys/vnode.h>
  49   51  #include <sys/sunddi.h>
  50   52  
  51   53  #include <netsmb/smb_osdep.h>
  52   54  
  53   55  #include <netsmb/smb.h>
  54   56  #include <netsmb/smb_conn.h>
  55   57  #include <netsmb/smb_subr.h>
  56   58  
  57   59  /*
  58      - * Time & date conversion routines taken from msdosfs. Although leap
  59      - * year calculation is bogus, it's sufficient before 2100 :)
  60      - */
  61      -/*
  62      - * This is the format of the contents of the deTime field in the direntry
  63      - * structure.
  64      - * We don't use bitfields because we don't know how compilers for
  65      - * arbitrary machines will lay them out.
  66      - */
  67      -#define DT_2SECONDS_MASK        0x1F    /* seconds divided by 2 */
  68      -#define DT_2SECONDS_SHIFT       0
  69      -#define DT_MINUTES_MASK         0x7E0   /* minutes */
  70      -#define DT_MINUTES_SHIFT        5
  71      -#define DT_HOURS_MASK           0xF800  /* hours */
  72      -#define DT_HOURS_SHIFT          11
  73      -
  74      -/*
  75      - * This is the format of the contents of the deDate field in the direntry
  76      - * structure.
  77      - */
  78      -#define DD_DAY_MASK             0x1F    /* day of month */
  79      -#define DD_DAY_SHIFT            0
  80      -#define DD_MONTH_MASK           0x1E0   /* month */
  81      -#define DD_MONTH_SHIFT          5
  82      -#define DD_YEAR_MASK            0xFE00  /* year - 1980 */
  83      -#define DD_YEAR_SHIFT           9
  84      -/*
  85      - * Total number of days that have passed for each month in a regular year.
  86      - */
  87      -static ushort_t regyear[] = {
  88      -        31, 59, 90, 120, 151, 181,
  89      -        212, 243, 273, 304, 334, 365
  90      -};
  91      -
  92      -/*
  93      - * Total number of days that have passed for each month in a leap year.
  94      - */
  95      -static ushort_t leapyear[] = {
  96      -        31, 60, 91, 121, 152, 182,
  97      -        213, 244, 274, 305, 335, 366
  98      -};
  99      -
 100      -/*
 101      - * Variables used to remember parts of the last time conversion.  Maybe we
 102      - * can avoid a full conversion.
 103      - */
 104      -static ulong_t  lasttime;
 105      -static ulong_t  lastday;
 106      -static ushort_t lastddate;
 107      -static ushort_t lastdtime;
 108      -
 109      -/* Lock for the lastxxx variables */
 110      -static kmutex_t lastdt_lock;
 111      -
 112      -/*
 113   60   * Number of seconds between 1970 and 1601 year
 114   61   * (134774 days)
 115   62   */
 116   63  const uint64_t DIFF1970TO1601 = 11644473600ULL;
 117   64  const uint32_t TEN_MIL = 10000000UL;
 118   65  
 119   66  /*
 120   67   * Convert NT time (tenths of microseconds since 1601)
 121   68   * to Unix seconds+nanoseconds since 1970.  Any time
 122   69   * earlier than 1970 is converted to Unix time zero.
↓ open down ↓ 62 lines elided ↑ open up ↑
 185  132  }
 186  133  
 187  134  void
 188  135  smb_time_server2local(ulong_t seconds, int tzoff, struct timespec *tsp)
 189  136  {
 190  137          if (seconds == 0)
 191  138                  tsp->tv_sec = 0;
 192  139          else
 193  140                  tsp->tv_sec = seconds + tzoff * 60;
 194  141          tsp->tv_nsec = 0;
 195      -}
 196      -
 197      -/*
 198      - * Time conversions to/from DOS format, for old dialects.
 199      - */
 200      -
 201      -void
 202      -smb_time_unix2dos(struct timespec *tsp, int tzoff, u_int16_t *ddp,
 203      -        u_int16_t *dtp, u_int8_t *dhp)
 204      -{
 205      -        long t;
 206      -        ulong_t days, year, month, inc;
 207      -        ushort_t *months;
 208      -
 209      -        mutex_enter(&lastdt_lock);
 210      -
 211      -        /*
 212      -         * If the time from the last conversion is the same as now, then
 213      -         * skip the computations and use the saved result.
 214      -         */
 215      -        smb_time_local2server(tsp, tzoff, &t);
 216      -        t &= ~1;
 217      -        if (lasttime != t) {
 218      -                lasttime = t;
 219      -                if (t < 0) {
 220      -                        /*
 221      -                         * This is before 1970, so it's before 1980,
 222      -                         * and can't be represented as a DOS time.
 223      -                         * Just represent it as the DOS epoch.
 224      -                         */
 225      -                        lastdtime = 0;
 226      -                        lastddate = (1 << DD_DAY_SHIFT)
 227      -                            + (1 << DD_MONTH_SHIFT)
 228      -                            + ((1980 - 1980) << DD_YEAR_SHIFT);
 229      -                } else {
 230      -                        lastdtime = (((t / 2) % 30) << DT_2SECONDS_SHIFT)
 231      -                            + (((t / 60) % 60) << DT_MINUTES_SHIFT)
 232      -                            + (((t / 3600) % 24) << DT_HOURS_SHIFT);
 233      -
 234      -                        /*
 235      -                         * If the number of days since 1970 is the same as
 236      -                         * the last time we did the computation then skip
 237      -                         * all this leap year and month stuff.
 238      -                         */
 239      -                        days = t / (24 * 60 * 60);
 240      -                        if (days != lastday) {
 241      -                                lastday = days;
 242      -                                for (year = 1970; ; year++) {
 243      -                                        /*
 244      -                                         * XXX - works in 2000, but won't
 245      -                                         * work in 2100.
 246      -                                         */
 247      -                                        inc = year & 0x03 ? 365 : 366;
 248      -                                        if (days < inc)
 249      -                                                break;
 250      -                                        days -= inc;
 251      -                                }
 252      -                                /*
 253      -                                 * XXX - works in 2000, but won't work in 2100.
 254      -                                 */
 255      -                                months = year & 0x03 ? regyear : leapyear;
 256      -                                for (month = 0; days >= months[month]; month++)
 257      -                                        ;
 258      -                                if (month > 0)
 259      -                                        days -= months[month - 1];
 260      -                                lastddate = ((days + 1) << DD_DAY_SHIFT)
 261      -                                    + ((month + 1) << DD_MONTH_SHIFT);
 262      -                                /*
 263      -                                 * Remember DOS's idea of time is relative
 264      -                                 * to 1980, but UN*X's is relative to 1970.
 265      -                                 * If somehow we get a time before 1980 then
 266      -                                 * don't give totally crazy results.
 267      -                                 */
 268      -                                if (year > 1980)
 269      -                                        lastddate += (year - 1980) <<
 270      -                                            DD_YEAR_SHIFT;
 271      -                        }
 272      -                }
 273      -        }
 274      -        if (dhp)
 275      -                *dhp = (tsp->tv_sec & 1) * 100 + tsp->tv_nsec / 10000000;
 276      -
 277      -        *ddp = lastddate;
 278      -        *dtp = lastdtime;
 279      -
 280      -        mutex_exit(&lastdt_lock);
 281      -}
 282      -
 283      -/*
 284      - * The number of seconds between Jan 1, 1970 and Jan 1, 1980. In that
 285      - * interval there were 8 regular years and 2 leap years.
 286      - */
 287      -#define SECONDSTO1980   (((8 * 365) + (2 * 366)) * (24 * 60 * 60))
 288      -
 289      -static ushort_t lastdosdate;
 290      -static ulong_t  lastseconds;
 291      -
 292      -void
 293      -smb_dos2unixtime(uint_t dd, uint_t dt, uint_t dh, int tzoff,
 294      -        struct timespec *tsp)
 295      -{
 296      -        ulong_t seconds;
 297      -        ulong_t month;
 298      -        ulong_t year;
 299      -        ulong_t days;
 300      -        ushort_t *months;
 301      -
 302      -        if (dd == 0) {
 303      -                tsp->tv_sec = 0;
 304      -                tsp->tv_nsec = 0;
 305      -                return;
 306      -        }
 307      -        seconds = (((dt & DT_2SECONDS_MASK) >> DT_2SECONDS_SHIFT) << 1)
 308      -            + ((dt & DT_MINUTES_MASK) >> DT_MINUTES_SHIFT) * 60
 309      -            + ((dt & DT_HOURS_MASK) >> DT_HOURS_SHIFT) * 3600
 310      -            + dh / 100;
 311      -
 312      -        /*
 313      -         * If the year, month, and day from the last conversion are the
 314      -         * same then use the saved value.
 315      -         */
 316      -        mutex_enter(&lastdt_lock);
 317      -        if (lastdosdate != dd) {
 318      -                lastdosdate = (ushort_t)dd;
 319      -                days = 0;
 320      -                year = (dd & DD_YEAR_MASK) >> DD_YEAR_SHIFT;
 321      -                days = year * 365;
 322      -                days += year / 4 + 1;   /* add in leap days */
 323      -                /*
 324      -                 * XXX - works in 2000, but won't work in 2100.
 325      -                 */
 326      -                if ((year & 0x03) == 0)
 327      -                        days--;         /* if year is a leap year */
 328      -                months = year & 0x03 ? regyear : leapyear;
 329      -                month = (dd & DD_MONTH_MASK) >> DD_MONTH_SHIFT;
 330      -                if (month < 1 || month > 12) {
 331      -                        month = 1;
 332      -                }
 333      -                if (month > 1)
 334      -                        days += months[month - 2];
 335      -                days += ((dd & DD_DAY_MASK) >> DD_DAY_SHIFT) - 1;
 336      -                lastseconds = (days * 24 * 60 * 60) + SECONDSTO1980;
 337      -        }
 338      -        smb_time_server2local(seconds + lastseconds, tzoff, tsp);
 339      -        tsp->tv_nsec = (dh % 100) * 10000000;
 340      -        mutex_exit(&lastdt_lock);
 341      -}
 342      -
 343      -void
 344      -smb_time_init(void)
 345      -{
 346      -        mutex_init(&lastdt_lock, NULL, MUTEX_DEFAULT, NULL);
 347      -}
 348      -
 349      -void
 350      -smb_time_fini(void)
 351      -{
 352      -        mutex_destroy(&lastdt_lock);
 353  142  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX