Ignore:
Timestamp:
Apr 7, 2008, 9:33:39 AM (17 years ago)
Author:
Yuri Dario
Message:

Fixes timezone handling for os2->xp->os2, os2->samba->os2. Partially fixes ticket:56.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.0/source/ndpsmb/ndpsmb.c

    r123 r126  
    1212#define NULL ((void *)0)
    1313
     14#ifndef DEBUG_PRINTF
     15#define debug_printf( ...)
     16#endif
     17
    1418void log(const char *fmt, ...)
    1519
     
    3943}
    4044
     45// -------------------------------------------------------------
     46
     47/* time conversion functions: SMB protocol sends timestamps in GMT time,
     48*  os2 api uses localtime,
     49*  emx/klibc uses timezone and daylight saving to convert GMT timestamps,
     50*  so only the timezone must be counted in conversion.
     51*/
     52void fsphUnixTimeToDosDate( time_t time, FDATE* fdate, FTIME *ftime)
     53{
     54    struct tm* gmt = localtime( &time);
     55    if (gmt->tm_isdst>0) {
     56        debug_printf( "daylight saving in effect %d, timezone %d\n",gmt->tm_isdst, timezone);
     57        time -= 3600;
     58        gmt = localtime( &time);
     59    }
     60    fdate->day  = gmt->tm_mday;
     61    fdate->month  = gmt->tm_mon+1;
     62    fdate->year = gmt->tm_year + 1900 - 1980;
     63    ftime->twosecs = gmt->tm_sec/2;
     64    ftime->minutes = gmt->tm_min;
     65    ftime->hours = gmt->tm_hour;
     66}
     67
     68void fsphDosDateToUnixTime( FDATE fdate, FTIME ftime, unsigned long* time)
     69{
     70    struct tm gmtime = { 0 };
     71    struct tm* gmt;
     72
     73    debug_printf( "fsphDosDateToUnixTime time %02d:%02d\n", ftime.hours, ftime.minutes);
     74    gmtime.tm_mday = fdate.day;
     75    gmtime.tm_mon = fdate.month-1;
     76    gmtime.tm_year = fdate.year + 1980 - 1900;
     77    gmtime.tm_sec = ftime.twosecs*2;
     78    gmtime.tm_min = ftime.minutes;
     79    gmtime.tm_hour = ftime.hours;
     80    gmtime.tm_isdst = -1; // force libc to check dst saving
     81
     82    *time = mktime( &gmtime);
     83    debug_printf( "fsphDosDateToUnixTime time1 %d %s", *time, ctime( time));
     84    gmt = localtime( (time_t*) time);
     85    if (gmt->tm_isdst>0) {
     86        debug_printf( "fsphDosDateToUnixTime daylight saving in effect %d, timezone %d\n",gmt->tm_isdst, timezone);
     87        *time += 3600;
     88    }
     89    debug_printf( "fsphDosDateToUnixTime time2 %d %s", *time, ctime( time));
     90}
     91
     92// -------------------------------------------------------------
     93       
    4194int StrLen(char * s)
    4295{
     
    339392        stat->attrFile = (finfo->attr & 0x37);
    340393
    341         ph->fsphUnixTimeToDosDate(finfo->mtime, &stat->fdateLastWrite, &stat->ftimeLastWrite);
    342         ph->fsphUnixTimeToDosDate(finfo->ctime, &stat->fdateCreation, &stat->ftimeCreation);
    343         ph->fsphUnixTimeToDosDate(finfo->atime, &stat->fdateLastAccess, &stat->ftimeLastAccess);
     394        fsphUnixTimeToDosDate(finfo->mtime, &stat->fdateLastWrite, &stat->ftimeLastWrite);
     395        fsphUnixTimeToDosDate(finfo->ctime, &stat->fdateCreation, &stat->ftimeCreation);
     396        fsphUnixTimeToDosDate(finfo->atime, &stat->fdateLastAccess, &stat->ftimeLastAccess);
    344397}
    345398
     
    369422        stat.attrFile = (finfo->attr & 0x37);
    370423
    371         ph->fsphUnixTimeToDosDate(finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
    372         ph->fsphUnixTimeToDosDate(finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
    373         ph->fsphUnixTimeToDosDate(finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
     424        fsphUnixTimeToDosDate(finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
     425        fsphUnixTimeToDosDate(finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
     426        fsphUnixTimeToDosDate(finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
     427        debug_printf( "fname %s\n", finfo->fname);
     428        debug_printf( "mtime %d %s", finfo->mtime, ctime( &finfo->mtime));
     429        debug_printf( "ftimeLastAccess %02d:%02d:%02d\n", stat.ftimeLastWrite.hours, stat.ftimeLastWrite.minutes, stat.ftimeLastWrite.twosecs*2);
    374430
    375431        ph->fsphAddFile32L(plist, &stat, name, StrLen(name), finfo, sizeof(*finfo), 0);
     
    11791235        NDPATHELEMENT *pel = ph->fsphNameElem(0);
    11801236
    1181         log("NdpFindStart in\n");
     1237        debug_printf("NdpFindStart in\n");
    11821238        do
    11831239        {
     
    12821338        do
    12831339          {
    1284                 log("NdpQueryInfo in <%s>, retry = %d\n", szPath, retry);
     1340                debug_printf("NdpQueryInfo in <%s>, retry = %d\n", szPath, retry);
    12851341
    12861342                do {
     
    14141470        char path[CCHMAXPATH+1] = {0};
    14151471
    1416         log("NdpSetPathInfo in\n");
     1472        debug_printf("NdpSetPathInfo in\n");
    14171473        do {
    14181474                rc = checkconnection(pConn);
     
    14311487
    14321488                StrNCpy(finfo->fname, path, sizeof(finfo->fname) - 1);
    1433                 ph->fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, (unsigned long *)&(finfo->mtime));
     1489                fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(finfo->mtime));
    14341490                if (ifL)
    14351491                {
     
    21402196        smbwrp_fileinfo * finfo = (smbwrp_fileinfo *)(pConn->mem + sizeof(pConn->file));
    21412197
    2142         log("NdpFileQueryInfo in\n");
     2198        debug_printf("NdpFileQueryInfo in\n");
    21432199        do {
    21442200                if (pConn->file.fd < 0 || !*pConn->file.fname)
     
    23812437        smbwrp_fileinfo * finfo = (smbwrp_fileinfo *)pConn->mem;
    23822438
    2383         log("NdpFileSetInfo in\n");
     2439        debug_printf("NdpFileSetInfo in\n");
    23842440        do {
    23852441                if (pConn->file.fd < 0 || !*pConn->file.fname)
     
    24042460                // deferred setinfo - on closing the file
    24052461                pConn->file.openattr = attrFile;
    2406                 ph->fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, (unsigned long *)&(pConn->file.mtime));
     2462                fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(pConn->file.mtime));
     2463                debug_printf("NdpFileSetInfo mtime %d\n", pConn->file.mtime);
    24072464        } while (0);
    24082465        log("NdpFileSetInfo <%s> %08x %d %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, attrFile, rc, pConn->rc);
Note: See TracChangeset for help on using the changeset viewer.