@@ -909,3 +909,54 @@ cifs_UnixTimeToNT(struct timespec t)
909909 /* Convert to 100ns intervals and then add the NTFS time offset. */
910910 return (u64 ) t .tv_sec * 10000000 + t .tv_nsec /100 + NTFS_TIME_OFFSET ;
911911}
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+ }
0 commit comments