Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  linux/fs/isofs/util.c
0004  */
0005 
0006 #include <linux/time.h>
0007 #include "isofs.h"
0008 
0009 /* 
0010  * We have to convert from a MM/DD/YY format to the Unix ctime format.
0011  * We have to take into account leap years and all of that good stuff.
0012  * Unfortunately, the kernel does not have the information on hand to
0013  * take into account daylight savings time, but it shouldn't matter.
0014  * The time stored should be localtime (with or without DST in effect),
0015  * and the timezone offset should hold the offset required to get back
0016  * to GMT.  Thus  we should always be correct.
0017  */
0018 
0019 int iso_date(u8 *p, int flag)
0020 {
0021     int year, month, day, hour, minute, second, tz;
0022     int crtime;
0023 
0024     year = p[0];
0025     month = p[1];
0026     day = p[2];
0027     hour = p[3];
0028     minute = p[4];
0029     second = p[5];
0030     if (flag == 0) tz = p[6]; /* High sierra has no time zone */
0031     else tz = 0;
0032     
0033     if (year < 0) {
0034         crtime = 0;
0035     } else {
0036         crtime = mktime64(year+1900, month, day, hour, minute, second);
0037 
0038         /* sign extend */
0039         if (tz & 0x80)
0040             tz |= (-1 << 8);
0041         
0042         /* 
0043          * The timezone offset is unreliable on some disks,
0044          * so we make a sanity check.  In no case is it ever
0045          * more than 13 hours from GMT, which is 52*15min.
0046          * The time is always stored in localtime with the
0047          * timezone offset being what get added to GMT to
0048          * get to localtime.  Thus we need to subtract the offset
0049          * to get to true GMT, which is what we store the time
0050          * as internally.  On the local system, the user may set
0051          * their timezone any way they wish, of course, so GMT
0052          * gets converted back to localtime on the receiving
0053          * system.
0054          *
0055          * NOTE: mkisofs in versions prior to mkisofs-1.10 had
0056          * the sign wrong on the timezone offset.  This has now
0057          * been corrected there too, but if you are getting screwy
0058          * results this may be the explanation.  If enough people
0059          * complain, a user configuration option could be added
0060          * to add the timezone offset in with the wrong sign
0061          * for 'compatibility' with older discs, but I cannot see how
0062          * it will matter that much.
0063          *
0064          * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann)
0065          * for pointing out the sign error.
0066          */
0067         if (-52 <= tz && tz <= 52)
0068             crtime -= tz * 15 * 60;
0069     }
0070     return crtime;
0071 }