diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/isofs/util.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'fs/isofs/util.c')
-rw-r--r-- | fs/isofs/util.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/fs/isofs/util.c b/fs/isofs/util.c new file mode 100644 index 000000000000..3f6d9c1ac95a --- /dev/null +++ b/fs/isofs/util.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * linux/fs/isofs/util.c | ||
3 | */ | ||
4 | |||
5 | #include <linux/time.h> | ||
6 | #include <linux/fs.h> | ||
7 | #include <linux/iso_fs.h> | ||
8 | |||
9 | /* | ||
10 | * We have to convert from a MM/DD/YY format to the Unix ctime format. | ||
11 | * We have to take into account leap years and all of that good stuff. | ||
12 | * Unfortunately, the kernel does not have the information on hand to | ||
13 | * take into account daylight savings time, but it shouldn't matter. | ||
14 | * The time stored should be localtime (with or without DST in effect), | ||
15 | * and the timezone offset should hold the offset required to get back | ||
16 | * to GMT. Thus we should always be correct. | ||
17 | */ | ||
18 | |||
19 | int iso_date(char * p, int flag) | ||
20 | { | ||
21 | int year, month, day, hour, minute, second, tz; | ||
22 | int crtime, days, i; | ||
23 | |||
24 | year = p[0] - 70; | ||
25 | month = p[1]; | ||
26 | day = p[2]; | ||
27 | hour = p[3]; | ||
28 | minute = p[4]; | ||
29 | second = p[5]; | ||
30 | if (flag == 0) tz = p[6]; /* High sierra has no time zone */ | ||
31 | else tz = 0; | ||
32 | |||
33 | if (year < 0) { | ||
34 | crtime = 0; | ||
35 | } else { | ||
36 | int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; | ||
37 | |||
38 | days = year * 365; | ||
39 | if (year > 2) | ||
40 | days += (year+1) / 4; | ||
41 | for (i = 1; i < month; i++) | ||
42 | days += monlen[i-1]; | ||
43 | if (((year+2) % 4) == 0 && month > 2) | ||
44 | days++; | ||
45 | days += day - 1; | ||
46 | crtime = ((((days * 24) + hour) * 60 + minute) * 60) | ||
47 | + second; | ||
48 | |||
49 | /* sign extend */ | ||
50 | if (tz & 0x80) | ||
51 | tz |= (-1 << 8); | ||
52 | |||
53 | /* | ||
54 | * The timezone offset is unreliable on some disks, | ||
55 | * so we make a sanity check. In no case is it ever | ||
56 | * more than 13 hours from GMT, which is 52*15min. | ||
57 | * The time is always stored in localtime with the | ||
58 | * timezone offset being what get added to GMT to | ||
59 | * get to localtime. Thus we need to subtract the offset | ||
60 | * to get to true GMT, which is what we store the time | ||
61 | * as internally. On the local system, the user may set | ||
62 | * their timezone any way they wish, of course, so GMT | ||
63 | * gets converted back to localtime on the receiving | ||
64 | * system. | ||
65 | * | ||
66 | * NOTE: mkisofs in versions prior to mkisofs-1.10 had | ||
67 | * the sign wrong on the timezone offset. This has now | ||
68 | * been corrected there too, but if you are getting screwy | ||
69 | * results this may be the explanation. If enough people | ||
70 | * complain, a user configuration option could be added | ||
71 | * to add the timezone offset in with the wrong sign | ||
72 | * for 'compatibility' with older discs, but I cannot see how | ||
73 | * it will matter that much. | ||
74 | * | ||
75 | * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann) | ||
76 | * for pointing out the sign error. | ||
77 | */ | ||
78 | if (-52 <= tz && tz <= 52) | ||
79 | crtime -= tz * 15 * 60; | ||
80 | } | ||
81 | return crtime; | ||
82 | } | ||
83 | |||