~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/fs/isofs/util.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/fs/isofs/util.c
  3  *
  4  *  The special functions in the file are numbered according to the section
  5  *  of the iso 9660 standard in which they are described.  isonum_733 will
  6  *  convert numbers according to section 7.3.3, etc.
  7  *
  8  *  isofs special functions.  This file was lifted in its entirety from
  9  *  the 386BSD iso9660 filesystem, by Pace Willisson <pace@blitz.com>.
 10  */
 11 
 12 #include <linux/time.h>
 13 
 14 int
 15 isonum_711 (char * p)
 16 {
 17         return (*p & 0xff);
 18 }
 19 
 20 int
 21 isonum_712 (char * p)
 22 {
 23         int val;
 24         
 25         val = *p;
 26         if (val & 0x80)
 27                 val |= 0xffffff00;
 28         return (val);
 29 }
 30 
 31 int
 32 isonum_721 (char * p)
 33 {
 34         return ((p[0] & 0xff) | ((p[1] & 0xff) << 8));
 35 }
 36 
 37 int
 38 isonum_722 (char * p)
 39 {
 40         return (((p[0] & 0xff) << 8) | (p[1] & 0xff));
 41 }
 42 
 43 int
 44 isonum_723 (char * p)
 45 {
 46 #if 0
 47         if (p[0] != p[3] || p[1] != p[2]) {
 48                 fprintf (stderr, "invalid format 7.2.3 number\n");
 49                 exit (1);
 50         }
 51 #endif
 52         return (isonum_721 (p));
 53 }
 54 
 55 int
 56 isonum_731 (char * p)
 57 {
 58         return ((p[0] & 0xff)
 59                 | ((p[1] & 0xff) << 8)
 60                 | ((p[2] & 0xff) << 16)
 61                 | ((p[3] & 0xff) << 24));
 62 }
 63 
 64 int
 65 isonum_732 (char * p)
 66 {
 67         return (((p[0] & 0xff) << 24)
 68                 | ((p[1] & 0xff) << 16)
 69                 | ((p[2] & 0xff) << 8)
 70                 | (p[3] & 0xff));
 71 }
 72 
 73 int
 74 isonum_733 (char * p)
 75 {
 76 #if 0
 77         int i;
 78 
 79         for (i = 0; i < 4; i++) {
 80                 if (p[i] != p[7-i]) {
 81                         fprintf (stderr, "bad format 7.3.3 number\n");
 82                         exit (1);
 83                 }
 84         }
 85 #endif
 86         return (isonum_731 (p));
 87 }
 88 
 89 /* 
 90  * We have to convert from a MM/DD/YY format to the Unix ctime format.
 91  * We have to take into account leap years and all of that good stuff.
 92  * Unfortunately, the kernel does not have the information on hand to
 93  * take into account daylight savings time, but it shouldn't matter.
 94  * The time stored should be localtime (with or without DST in effect),
 95  * and the timezone offset should hold the offset required to get back
 96  * to GMT.  Thus  we should always be correct.
 97  */
 98 
 99 int iso_date(char * p, int flag)
100 {
101         int year, month, day, hour, minute, second, tz;
102         int crtime, days, i;
103 
104         year = p[0] - 70;
105         month = p[1];
106         day = p[2];
107         hour = p[3];
108         minute = p[4];
109         second = p[5];
110         if (flag == 0) tz = p[6]; /* High sierra has no time zone */
111         else tz = 0;
112         
113         if (year < 0) {
114                 crtime = 0;
115         } else {
116                 int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
117 
118                 days = year * 365;
119                 if (year > 2)
120                         days += (year+1) / 4;
121                 for (i = 1; i < month; i++)
122                         days += monlen[i-1];
123                 if (((year+2) % 4) == 0 && month > 2)
124                         days++;
125                 days += day - 1;
126                 crtime = ((((days * 24) + hour) * 60 + minute) * 60)
127                         + second;
128 
129                 /* sign extend */
130                 if (tz & 0x80)
131                         tz |= (-1 << 8);
132                 
133                 /* 
134                  * The timezone offset is unreliable on some disks,
135                  * so we make a sanity check.  In no case is it ever
136                  * more than 13 hours from GMT, which is 52*15min.
137                  * The time is always stored in localtime with the
138                  * timezone offset being what get added to GMT to
139                  * get to localtime.  Thus we need to subtract the offset
140                  * to get to true GMT, which is what we store the time
141                  * as internally.  On the local system, the user may set
142                  * their timezone any way they wish, of course, so GMT
143                  * gets converted back to localtime on the receiving
144                  * system.
145                  *
146                  * NOTE: mkisofs in versions prior to mkisofs-1.10 had
147                  * the sign wrong on the timezone offset.  This has now
148                  * been corrected there too, but if you are getting screwy
149                  * results this may be the explanation.  If enough people
150                  * complain, a user configuration option could be added
151                  * to add the timezone offset in with the wrong sign
152                  * for 'compatibility' with older discs, but I cannot see how
153                  * it will matter that much.
154                  *
155                  * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann)
156                  * for pointing out the sign error.
157                  */
158                 if (-52 <= tz && tz <= 52)
159                         crtime -= tz * 15 * 60;
160         }
161         return crtime;
162 }               
163         
164 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.