util.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * linux/fs/isofs/util.c
  3. */
  4. #include <linux/time.h>
  5. #include <linux/fs.h>
  6. #include <linux/iso_fs.h>
  7. /*
  8. * We have to convert from a MM/DD/YY format to the Unix ctime format.
  9. * We have to take into account leap years and all of that good stuff.
  10. * Unfortunately, the kernel does not have the information on hand to
  11. * take into account daylight savings time, but it shouldn't matter.
  12. * The time stored should be localtime (with or without DST in effect),
  13. * and the timezone offset should hold the offset required to get back
  14. * to GMT. Thus we should always be correct.
  15. */
  16. int iso_date(char * p, int flag)
  17. {
  18. int year, month, day, hour, minute, second, tz;
  19. int crtime, days, i;
  20. year = p[0] - 70;
  21. month = p[1];
  22. day = p[2];
  23. hour = p[3];
  24. minute = p[4];
  25. second = p[5];
  26. if (flag == 0) tz = p[6]; /* High sierra has no time zone */
  27. else tz = 0;
  28. if (year < 0) {
  29. crtime = 0;
  30. } else {
  31. int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
  32. days = year * 365;
  33. if (year > 2)
  34. days += (year+1) / 4;
  35. for (i = 1; i < month; i++)
  36. days += monlen[i-1];
  37. if (((year+2) % 4) == 0 && month > 2)
  38. days++;
  39. days += day - 1;
  40. crtime = ((((days * 24) + hour) * 60 + minute) * 60)
  41. + second;
  42. /* sign extend */
  43. if (tz & 0x80)
  44. tz |= (-1 << 8);
  45. /*
  46. * The timezone offset is unreliable on some disks,
  47. * so we make a sanity check. In no case is it ever
  48. * more than 13 hours from GMT, which is 52*15min.
  49. * The time is always stored in localtime with the
  50. * timezone offset being what get added to GMT to
  51. * get to localtime. Thus we need to subtract the offset
  52. * to get to true GMT, which is what we store the time
  53. * as internally. On the local system, the user may set
  54. * their timezone any way they wish, of course, so GMT
  55. * gets converted back to localtime on the receiving
  56. * system.
  57. *
  58. * NOTE: mkisofs in versions prior to mkisofs-1.10 had
  59. * the sign wrong on the timezone offset. This has now
  60. * been corrected there too, but if you are getting screwy
  61. * results this may be the explanation. If enough people
  62. * complain, a user configuration option could be added
  63. * to add the timezone offset in with the wrong sign
  64. * for 'compatibility' with older discs, but I cannot see how
  65. * it will matter that much.
  66. *
  67. * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann)
  68. * for pointing out the sign error.
  69. */
  70. if (-52 <= tz && tz <= 52)
  71. crtime -= tz * 15 * 60;
  72. }
  73. return crtime;
  74. }