diff options
author | Steve French <sfrench@us.ibm.com> | 2006-09-27 23:35:57 -0400 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2006-09-27 23:35:57 -0400 |
commit | 1bd5bbcb6531776a8f73e2cc6287fc4dd542e1c7 (patch) | |
tree | 7c41514f13224d6292a1bb90636f44c3c027b2e8 /fs/cifs/netmisc.c | |
parent | 0889a9441d98af7951c5377647413d79c84c9efa (diff) |
[CIFS] Legacy time handling for Win9x and OS/2 part 1
Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs/netmisc.c')
-rw-r--r-- | fs/cifs/netmisc.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index ce87550e918f..fa5124d9af19 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c | |||
@@ -909,3 +909,54 @@ cifs_UnixTimeToNT(struct timespec t) | |||
909 | /* Convert to 100ns intervals and then add the NTFS time offset. */ | 909 | /* Convert to 100ns intervals and then add the NTFS time offset. */ |
910 | return (u64) t.tv_sec * 10000000 + t.tv_nsec/100 + NTFS_TIME_OFFSET; | 910 | return (u64) t.tv_sec * 10000000 + t.tv_nsec/100 + NTFS_TIME_OFFSET; |
911 | } | 911 | } |
912 | |||
913 | static int total_days_of_prev_months[] = | ||
914 | {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; | ||
915 | |||
916 | |||
917 | __le64 cnvrtDosCifsTm(__u16 date, __u16 time) | ||
918 | { | ||
919 | return cpu_to_le64(cifs_UnixTimeToNT(cnvrtDosUnixTm(date, time))); | ||
920 | } | ||
921 | struct timespec cnvrtDosUnixTm(__u16 date, __u16 time) | ||
922 | { | ||
923 | __u8 dt[2]; | ||
924 | __u8 tm[2]; | ||
925 | struct timespec ts; | ||
926 | int sec,min, days, month, year; | ||
927 | struct timespec removeme; /* BB removeme BB */ | ||
928 | /* SMB_TIME * st = (SMB_TIME *)&time;*/ | ||
929 | |||
930 | cFYI(1,("date %d time %d",date, time)); | ||
931 | |||
932 | dt[0] = date & 0xFF; | ||
933 | dt[1] = (date & 0xFF00) >> 8; | ||
934 | tm[0] = time & 0xFF; | ||
935 | tm[1] = (time & 0xFF00) >> 8; | ||
936 | |||
937 | sec = tm[0] & 0x1F; | ||
938 | sec = 2 * sec; | ||
939 | min = ((tm[0] >>5)&0xFF) + ((tm[1] & 0x7)<<3); | ||
940 | |||
941 | sec += (min * 60); | ||
942 | sec += 60 * 60 * ((tm[1] >> 3) &0xFF) /* hours */; | ||
943 | days = (dt[0] & 0x1F) - 1; | ||
944 | month = ((dt[0] >> 5) & 0xFF) + ((dt[1] & 0x1) <<3); | ||
945 | if(month > 12) | ||
946 | cERROR(1,("illegal month %d in date", month)); | ||
947 | month -= 1; | ||
948 | days += total_days_of_prev_months[month]; | ||
949 | days += 3653; /* account for difference in days between 1980 and 1970 */ | ||
950 | year = (dt[1]>>1) & 0xFF; | ||
951 | days += year * 365; | ||
952 | days += (year/4); /* leap year */ | ||
953 | /* adjust for leap year where we are still before leap day */ | ||
954 | days -= ((year & 0x03) == 0) && (month < 2 ? 1 : 0); | ||
955 | sec += 24 * 60 * 60 * days; | ||
956 | |||
957 | removeme = CURRENT_TIME; /* BB removeme BB */ | ||
958 | ts.tv_sec = sec; | ||
959 | |||
960 | ts.tv_nsec = 0; | ||
961 | return ts; | ||
962 | } | ||