util.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/isofs/util.c
  4. */
  5. #include <linux/time.h>
  6. #include "isofs.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(u8 *p, int flag)
  17. {
  18. int year, month, day, hour, minute, second, tz;
  19. int crtime;
  20. year = p[0];
  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. crtime = mktime64(year+1900, month, day, hour, minute, second);
  32. /* sign extend */
  33. if (tz & 0x80)
  34. tz |= (-1 << 8);
  35. /*
  36. * The timezone offset is unreliable on some disks,
  37. * so we make a sanity check. In no case is it ever
  38. * more than 13 hours from GMT, which is 52*15min.
  39. * The time is always stored in localtime with the
  40. * timezone offset being what get added to GMT to
  41. * get to localtime. Thus we need to subtract the offset
  42. * to get to true GMT, which is what we store the time
  43. * as internally. On the local system, the user may set
  44. * their timezone any way they wish, of course, so GMT
  45. * gets converted back to localtime on the receiving
  46. * system.
  47. *
  48. * NOTE: mkisofs in versions prior to mkisofs-1.10 had
  49. * the sign wrong on the timezone offset. This has now
  50. * been corrected there too, but if you are getting screwy
  51. * results this may be the explanation. If enough people
  52. * complain, a user configuration option could be added
  53. * to add the timezone offset in with the wrong sign
  54. * for 'compatibility' with older discs, but I cannot see how
  55. * it will matter that much.
  56. *
  57. * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann)
  58. * for pointing out the sign error.
  59. */
  60. if (-52 <= tz && tz <= 52)
  61. crtime -= tz * 15 * 60;
  62. }
  63. return crtime;
  64. }