util.c 2.1 KB

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