Ignore:
Timestamp:
Jun 10, 2010, 11:16:45 AM (15 years ago)
Author:
Silvan Scherrer
Message:

Samba Server 3.5: included os2helper from 3.3 instead of os2ea & os2path

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/lib/os2helper.c

    r454 r463  
    1 /* This file contains helper functions for OS/2 - don't try and compile on other platforms */
     1/* This file contains helper functions for OS/2 -
     2   do not try to compile on other platforms! */
    23
    34#ifdef __OS2__
     
    1011#define INCL_DOSMODULEMGR
    1112#define INCL_DOSERRORS
    12 //_SMB_H
     13
    1314#include <os2.h>
    1415#include <stdio.h>
     
    1617#include <errno.h>
    1718#include <types.h>
    18 
     19#include <string.h>
    1920//YD for tmalloc
    2021#include <malloc.h>
     
    4243#endif
    4344
    44 #include <string.h>
    45 
    4645#ifndef ENOATTR
    4746#define ENOATTR 22
     
    5049int os2_ftruncate(int fd, off_t size)
    5150{
    52         // We call there __libc_Back_ioFileSizeSet directly instead of
    53         // ftruncate to force it not to zero expanding files to optimize
    54         // samba performance when copying files
     51        /* We call __libc_Back_ioFileSizeSet directly instead of
     52           ftruncate to force it not to zero expanding files to optimize
     53           samba performance when copying files */
     54
    5555        int rc = __libc_Back_ioFileSizeSet(fd, size, 0);
    5656        if (rc < 0)
     
    9090         rc = DosFindClose(hdirFindHandle);    /* Close our directory handle */
    9191       return 1;
    92 
    9392    } else {
    9493         rc = DosFindClose(hdirFindHandle);    /* Close our directory handle */
    9594        return 0;
    96 
    9795    } /* endif */
    98 
    99 }
    100 
    101 /* Functions below are based on APR random code */
    102 /* Licensed to the Apache Software Foundation (ASF) under one or more
    103  * contributor license agreements.  See the NOTICE file distributed with
    104  * this work for additional information regarding copyright ownership.
    105  * The ASF licenses this file to You under the Apache License, Version 2.0
    106  * (the "License"); you may not use this file except in compliance with
    107  * the License.  You may obtain a copy of the License at
    108  *
    109  *     http://www.apache.org/licenses/LICENSE-2.0
    110  *
    111  * Unless required by applicable law or agreed to in writing, software
    112  * distributed under the License is distributed on an "AS IS" BASIS,
    113  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    114  * See the License for the specific language governing permissions and
    115  * limitations under the License.
    116  */
    117 
     96}
     97
     98// we search the path of the .exe and return it
     99int os2_GetExePath(char *buff)
     100{
     101        APIRET rc = NO_ERROR;
     102        PPIB ppib = NULL;
     103        char sExePath [_MAX_PATH];
     104        char sDrive [_MAX_PATH], sDir [_MAX_DIR];
     105
     106        // we search for the infoblock to get the module name
     107        rc = DosGetInfoBlocks(NULL, &ppib);
     108        if (rc != NO_ERROR)
     109        {
     110                return -1;
     111        }
     112
     113        // with the module name we get the path (including the exe name)
     114        rc = DosQueryModuleName(ppib->pib_hmte, sizeof(sExePath), sExePath);
     115        if (rc != NO_ERROR)
     116        {
     117                return -1;
     118        }
     119
     120        // we split to the different values
     121        _splitpath(sExePath, sDrive, sDir, NULL, NULL);
     122        // strcat(sDrive, sDir);
     123        strncat(sDrive, sDir, strlen(sDir) -1);
     124        strcpy(buff, sDrive);
     125
     126        return 0;
     127}
     128
     129/* OS/2-specific random functions. these functions used to be based on APR
     130   random code, but we discovered some nasty problems with it on fast hardware
     131   (especially on quadcore) and decided to rewrite it with libc random() */
     132 
    118133void os2_randget(char * buffer, int length)
    119134{
     
    126141}
    127142
    128 /* A bunch of system information like memory & process stats.
    129  * Not highly random but every bit helps....
    130  */
    131 static UCHAR randbyte_sysinfo()
    132 {
    133     UCHAR byte = 0;
    134     UCHAR SysVars[100];
    135     int b;
    136 
    137     DosQuerySysInfo(1, QSV_FOREGROUND_PROCESS, SysVars, sizeof(SysVars));
    138 
    139     for (b = 0; b < 100; b++) {
    140         byte ^= SysVars[b];
    141     }
    142 
    143     return byte;
    144 }
    145 
    146 
    147 
    148 /* Similar in concept to randbyte_hrtimer() but accesses the CPU's internal
    149  * counters which run at the CPU's MHz speed. We get separate
    150  * idle / busy / interrupt cycle counts which should provide very good
    151  * randomness due to interference of hardware events.
    152  * This only works on newer CPUs (at least PPro or K6) and newer OS/2 versions
    153  * which is why it's run-time linked.
    154  */
    155 
    156 static HMODULE hDoscalls = 0;
    157 #define   CMD_KI_RDCNT    (0x63)
    158 
    159 typedef struct _CPUUTIL {
    160     ULONG ulTimeLow;            /* Low 32 bits of time stamp      */
    161     ULONG ulTimeHigh;           /* High 32 bits of time stamp     */
    162     ULONG ulIdleLow;            /* Low 32 bits of idle time       */
    163     ULONG ulIdleHigh;           /* High 32 bits of idle time      */
    164     ULONG ulBusyLow;            /* Low 32 bits of busy time       */
    165     ULONG ulBusyHigh;           /* High 32 bits of busy time      */
    166     ULONG ulIntrLow;            /* Low 32 bits of interrupt time  */
    167     ULONG ulIntrHigh;           /* High 32 bits of interrupt time */
    168 } CPUUTIL;
    169 
    170 APIRET APIENTRY(*pfnDosPerfSysCall) (ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL;
    171 APIRET APIENTRY(*pfnDosQuerySysState) (ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL;
    172 
    173 static UCHAR randbyte_perf()
    174 {
    175     UCHAR byte = 0;
    176     CPUUTIL util;
    177     int c;
    178 
    179     if (hDoscalls == 0) {
    180         char failed_module[20];
    181         ULONG rc;
    182 
    183         rc = DosLoadModule(failed_module, sizeof(failed_module), "DOSCALLS",
    184                            &hDoscalls);
    185 
    186         if (rc == 0) {
    187             rc = DosQueryProcAddr(hDoscalls, 976, NULL, (PFN *)&pfnDosPerfSysCall);
    188 
    189             if (rc) {
    190                 pfnDosPerfSysCall = NULL;
    191             }
    192         }
    193     }
    194 
    195     if (pfnDosPerfSysCall) {
    196         if ((*pfnDosPerfSysCall) (CMD_KI_RDCNT, (ULONG)&util, 0, 0) == 0) {
    197             for (c = 0; c < sizeof(util); c++) {
    198                 byte ^= ((UCHAR *)&util)[c];
    199             }
    200         }
    201         else {
    202             pfnDosPerfSysCall = NULL;
    203         }
    204     }
    205 
    206     return byte;
    207 }
    208 
    209 
    210 
    211143UCHAR randbyte()
    212144{
    213     return randbyte_sysinfo() ^ randbyte_perf();
     145        int c;
     146        UCHAR byte;
     147        ULONG ulrandom;
     148        ulrandom = random();
     149       
     150        for (c = 0; c < sizeof(ulrandom); c++) {
     151                byte ^= ((UCHAR *)&ulrandom)[c];
     152        }
     153
     154        return byte;
    214155}
    215156
Note: See TracChangeset for help on using the changeset viewer.