void        DrvGetDriveName( ULONG ulDrive, char * pszText)

{
    ULONG       cbAU;
    char *      ptr;
    FSINFO      fsi;
    FSALLOCATE  fsa;
    char        szMB[16];

    if (!DosQueryFSInfo( (ulDrive - 0x40), FSIL_VOLSER, &fsi, sizeof(fsi)))
        ptr = fsi.vol.szVolLabel;
    else
        ptr = "";

    if (!DosQueryFSInfo( (ulDrive - 0x40), FSIL_ALLOC, &fsa, sizeof(fsa))) {
        LoadString( MSG_MB, szMB);
        cbAU = fsa.cSectorUnit * fsa.cbSector;
        sprintf( pszText, "%c:  %s  (%lu / %lu%s)", (char)ulDrive, ptr,
                 (((fsa.cUnit - fsa.cUnitAvail) * cbAU) + 500000) / 1000000,
                 ((fsa.cUnit * cbAU) + 500000) / 1000000, szMB);
    }
    else
        sprintf( pszText, "%c:  %s", (char)ulDrive, ptr);

    return;
}
unsigned long SysDriveInfo(unsigned char *name,
                           unsigned long numargs,
                           RXSTRING args[],
                           char *queuename,
                           RXSTRING *retstr)
{
    char *arg;                         /* Temp var for holding args  */
    unsigned char     buf[256];        /* Give DosQFSInfo 256 bytes  */

    unsigned long     drivenum;        /* Drive number (A=1, B=2,    */
                                       /* etc)                       */
    FSALLOCATE FSInfoBuf;              /* Structure required by      */
                                       /* DosQfsInfo                 */
    long      rc;                      /* OS/2 return code           */

#ifdef DLOGGING
    logmessage(__func__);
#endif

                                       /* validate arguments         */
    if (numargs != 1 || args[0].strlength > 2 ||
        args[0].strlength == 0) return INVALID_ROUTINE;

                                       /* validate the arg           */
    arg = args[0].strptr;              /* get argument pointer       */
                                       /* drive letter?              */

    if ((strlen(arg) == 2 && arg[1] != ':') ||
          !isalpha(arg[0])) return INVALID_ROUTINE;
    else drivenum = toupper(arg[0])-'A'+1;  /* Get the drive number       */

                                       /* query the disk             */
    DosError(0);                       /* Disable hard-error pop-up  */
                                       /* Get the drive info         */

    rc = DosQueryFSInfo(drivenum, 2, buf, sizeof(buf));
    DosQueryFSInfo(drivenum, 1, (char *)&FSInfoBuf, sizeof(FSInfoBuf));

    if (rc == 0 || rc == 125) {
        sprintf(retstr->strptr, "%c:  %-12lu %-12lu %-13s", (drivenum+'A'-1),
            FSInfoBuf.cSectorUnit * FSInfoBuf.cbSector *FSInfoBuf.cUnitAvail,
            FSInfoBuf.cSectorUnit * FSInfoBuf.cbSector *FSInfoBuf.cUnit, &buf[5]);
                                       /* create return string       */
        retstr->strlength = strlen(retstr->strptr);
    } else retstr->strlength = 0;             /* return null string         */

    DosError(1);                         /* Enable hard-error pop-up   */

    return VALID_ROUTINE;                /* no error on call           */

}
BOOL SetDisk(HWND hwnd, BYTE newDisk, PBOOL phpfs) {
   APIRET rc;
   BYTE buf[128];
   ULONG ulAct;
   CHAR ch = newDisk;
   newDisk = newDisk > 'Z'? newDisk - 'a' + 1: newDisk - 'A' + 1;
   DosError(0);                  // disabilita dialogo errore drive not ready
   rc = DosQueryFSInfo(newDisk, FSIL_VOLSER, buf, sizeof(buf));
   DosError(1);
   if (rc && rc != 125) {       // se drive not ready-> retry, cancel
      if (WinMessageBox(HWND_DESKTOP, hwnd, DRIVE_NOT_READY, NULL,
                        0, MB_RETRYCANCEL | MB_ERROR | MB_MOVEABLE) ==
          MBID_RETRY) {
         return SetDisk(hwnd, newDisk, phpfs);
      } else {
         return 1;
      } /* endif */
   } /* endif */
   DosSetDefaultDisk(newDisk);
   *phpfs = isHPFS(ch);
   if (hwnd != HWND_DESKTOP) {
      // mostra/nasconde data-ora creazione e ultimo accesso secondo FS
      DlgShowCtl(hwnd, STB_CREATED, *phpfs);
      DlgShowCtl(hwnd, STB_ACCESSED, *phpfs);
   } /* endif */
   return 0;
}
Exemple #4
0
unsigned long getfree (char *path)
{
  FSALLOCATE fsa;
  ULONG disknum = 0;
  APIRET rc;

  if (isalpha (path[0]) && path[1] == ':')
    disknum = toupper (path[0]) - 'A' + 1;

  rc = DosQueryFSInfo (disknum,		    /* Drive number            */
		       FSIL_ALLOC,	    /* Level 1 allocation info */
		       (PVOID) & fsa,	    /* Buffer                  */
		       sizeof (fsa));	    /* Size of buffer          */

  if (rc)
  {
    Log (1, "DosQueryFSInfo error: return code = %u", rc);
    return ULONG_MAX;			    /* Assume enough disk space */
  }
  else
  {
    if (fsa.cSectorUnit * fsa.cbSector >= 1024)
      return fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector / 1024);
    else
      return fsa.cUnitAvail / (1024 / (fsa.cSectorUnit * fsa.cbSector));
  }
}
Exemple #5
0
static int disc_is_inserted(ULONG drive)
{
    int rc;
    char buf[20];
    DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION);
    rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf));
    DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
    return(rc == NO_ERROR);
} /* is_cdrom_inserted */
Exemple #6
0
long LocalGetFreeSpace( int drv )
/*******************************/
{
    struct _FSALLOCATE usage;

    if( DosQueryFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) {
        return( -1 );
    }
    return( usage.cbSector * usage.cSectorUnit * usage.cUnitAvail );
}
Bool volume_open (char letter, volh *handle) {
   char openpath[8];
   ULONG  resAction,
                 rc;
   HFILE         dh;
   sprintf(openpath,"%c:",letter);

   DosError(FERR_DISABLEHARDERR);

   rc = DosOpen(openpath,&dh,&resAction,0,0,OPEN_ACTION_OPEN_IF_EXISTS,
      OPEN_FLAGS_DASD|OPEN_FLAGS_NO_CACHE|OPEN_FLAGS_NOINHERIT|
         OPEN_SHARE_DENYNONE|OPEN_FLAGS_FAIL_ON_ERROR|OPEN_ACCESS_READWRITE,0);
   // OPEN_SHARE_DENYREADWRITE
   if (rc==0)
   {
      voldata *vh = (voldata*)malloc(sizeof(voldata));
      struct { b Infotype, DriveUnit; } DriveRequest;
      d psize  = sizeof(DriveRequest),
        dsize  = sizeof(vh->bpb);

      memset(vh, 0, sizeof(voldata));
      vh->dh   = dh;

      /* good news is that real BPB returned with REAL sectors per track value,
         not written into FAT spt field. This is actual for 127/255 spt disks,
         formatted to FAT in Windows (where FAT spt is 63) */
      DriveRequest.Infotype =1; //0;
      DriveRequest.DriveUnit=0;

      if (DosDevIOCtl(dh,IOCTL_DISK,DSK_GETDEVICEPARAMS,(PVOID)&DriveRequest,
        sizeof(DriveRequest),&psize,(PVOID)&vh->bpb,sizeof(vh->bpb),&dsize)==0)
      {
         u64 sectors = vh->bpb.cSectors;
         if (!sectors) sectors = vh->bpb.cLargeSectors;
         vh->volsize = sectors;
         vh->ssize   = vh->bpb.usBytesPerSector;
      } else {
         FSALLOCATE    fa;
         if (DosQueryFSInfo(letter-'A'+1,FSIL_ALLOC,&fa,sizeof(fa)))
            memset(&fa,0,sizeof(fa));

         vh->volsize = ((u64)fa.cSectorUnit*fa.cbSector*fa.cUnit)/fa.cbSector;
         vh->ssize   = fa.cbSector;
      }

      vh->drive   = letter;
      *handle = vh;
      return True;
   } else {
      printf("Error %d (%X)\n",rc,rc);
   }

   *handle = 0;
   return False;
}
Exemple #8
0
 int main(VOID) {



 typedef struct _FSINFOBUF

  {  ULONG        ulVolser;   /* Volume serial number */

     VOLUMELABEL  vol;        /* Volume label         */

  } FSINFOBUF;

 typedef FSINFOBUF *PFSINFOBUF;



 ULONG       ulDriveNumber = 0;          /* Drive number */

 FSINFOBUF   VolumeInfo    = {0};        /* File system info buffer */

 APIRET      rc            = NO_ERROR;   /* Return code */



    ulDriveNumber = 3;          /* Specify drive C (A=1, B=2, C=3, ...) */



    rc = DosQueryFSInfo(ulDriveNumber,

                        FSIL_VOLSER,      /* Request volume information */

                        &VolumeInfo,      /* Buffer for information     */

                        sizeof(FSINFOBUF));  /* Size of buffer          */



    if (rc != NO_ERROR) {

        printf("DosQueryFSInfo error: return code = %u\n", rc);

        return 1;

    } else {

        printf("Volume label: %s\n", VolumeInfo.vol.szVolLabel);

    }

    return NO_ERROR;

  }
Exemple #9
0
BOOL fillDrvList(PINSTALLDATA pid, HWND hprgs) {
   char dev[4];
   FSALLOCATE fsa;
   BYTE buf[32];
   CHAR achdd[32];
   ULONG ulDriveNum = 0;
   ULONG ulDriveMap = 0;
   ULONG ul, idx, tot;
   int i, j, k;
   PFSQBUFFER2 pfsqb = (PFSQBUFFER2)buf;

   strcpy(dev, " :");
   DosError(0);
   DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
   // conta drive presenti
   for (i = 2, tot = 0; i < 26; ++i)
      tot += (ulDriveMap & 1L << i)? 1: 0;
   // per ogni drive presente raccogli informazioni
   for (i = 2, j = 0, k = 0, idx = 0; i < 26; i++) {// ripete x tutti i drive
//      DosSleep(1000);
      if (ulDriveMap & 1L << i) {            // se trova partizione
         if (Wincrease(&idx, hprgs, tot)) return FALSE;
         ul = 32;
         dev[0] = (CHAR)(i + 'A');
         if (DosQueryFSInfo(i + 1, FSIL_ALLOC, &fsa, sizeof(FSALLOCATE)))
            continue;        // se drive non disponibile passa a successivo
         DosQueryFSAttach((PSZ)dev, 1, FSAIL_QUERYNAME,
                          (PFSQBUFFER2)&buf, &ul);
         if (pfsqb->iType != 3 ||         // se non drive locale
             (strcmp(pfsqb->szName + 3, "FAT") &&    // o nŠ FAT
              strcmp(pfsqb->szName + 3, "HPFS") &&
              strcmp(pfsqb->szName + 3, "JFS")))    // e nŠ HPFS
            continue;                     // passa al successivo
         pid->cMbDrv[i] = (ULONG)((float)fsa.cbSector *
                                  (float)fsa.cSectorUnit *
                                  (float)fsa.cUnitAvail)
                                  / 1048576;
         sprintf(achdd, "%s % 15d MB", dev, pid->cMbDrv[i]);
         DlgLboxInsertItem(pid->hwnd, LBX_INSTDRV, LIT_END, achdd);
         // seleziona l'item corrispondente al drive menzionato in pad->path
         if (dev[0] == *pid->tpath) k = j;
         j++;
      } // end if
   } // end for
   Wincrease(&idx, hprgs, tot);
   DosError(1);
   DlgLboxSelectItem(pid->hwnd, LBX_INSTDRV, k);
   WinPostMsg(hprgs, PRGSM_END, MPVOID, MPVOID);
   return TRUE;
}
VOID QueryVolumeLabel (ULONG ulDriveNumber, PSZ pszVolumeLabel)
{
    FSINFO fsInfo;

    DosError (FERR_DISABLEHARDERR);

    if (!DosQueryFSInfo (ulDriveNumber, FSIL_VOLSER, &fsInfo, sizeof(FSINFO)))
        strcpy (pszVolumeLabel, fsInfo.vol.szVolLabel);
    else
        pszVolumeLabel[0] = '\0';

    DosError (FERR_ENABLEHARDERR);

    return;
}
Boolean driveValid(char drive) {
   drive = toupper(drive);
#ifdef __MSDOS__
   struct diskfree_t df;
   return Boolean(_dos_getdiskfree(drive-'@',&df) == 0);
#elif defined(__OS2__)
   FSALLOCATE a;
   return Boolean(!DosQueryFSInfo(drive - '@', FSIL_ALLOC, &a, sizeof(a)));
#elif defined(__NT__)
   DWORD mask = 0x01 << (drive - 'A');
   return (Boolean)(GetLogicalDrives() & mask);
#elif defined(__QSINIT__)
   return (Boolean)(io_ismounted(drive - 'A', 0));
#else
#error Unknown platform!
#endif
}
Exemple #12
0
int main (VOID) {

   ULONG   aulFSInfoBuf[40] = {0};         /* File system info buffer     */

   APIRET  rc               = NO_ERROR;    /* Return code                 */



   rc = DosQueryFSInfo(3L,                     /* Drive number 3 (C:)     */

                       FSIL_ALLOC,             /* Level 1 allocation info */

                       (PVOID)aulFSInfoBuf,    /* Buffer                  */

                       sizeof(aulFSInfoBuf));  /* Size of buffer          */



   if (rc != NO_ERROR) {

      printf("DosQueryFSInfo error: return code = %u\n", rc);

      return 1;

   } else {

      printf ("%12ld bytes in each allocation unit.\n",

               aulFSInfoBuf[1] * (USHORT)aulFSInfoBuf[4]);

             /* (Sectors per allocation unit) * (Bytes per sector) */

      printf ("%12ld total allocation units.\n", aulFSInfoBuf[2]);

      printf ("%12ld available allocation units on disk.\n", aulFSInfoBuf[3]);

   }

   DosExit(EXIT_THREAD,aulFSInfoBuf[3]);  /* Return available allocation units

                                             to the initiating process      */

   return NO_ERROR;

}
Exemple #13
0
/* --------------------------------------------------------------------------
 Return the amount of available space on a disk volume.
- Parameters -------------------------------------------------------------
 PSZ pszPath : path to be queried for the amount of free space.
- Return value -----------------------------------------------------------
 LONGLONG amount of available free space (-1 in case of error).
-------------------------------------------------------------------------- */
LONGLONG fmAvailSpace(PSZ pszPath, PULONG pCbSector) {
   FSALLOCATE fsa;
   ULONG ulDrvNum, ulDrvMap;

   if (!pszPath || (pszPath[1] != ':'))
      DosQueryCurrentDisk(&ulDrvNum, &ulDrvMap);
   else
      ulDrvNum = *pszPath & ~0x20 - 'A' + 1;
   g.rc = DosQueryFSInfo(ulDrvNum, FSIL_ALLOC, &fsa, sizeof(fsa));
   if (g.rc)
   {
      handleError(FALSE, FALSE, SZERR_QUERYFREESPACE, ulDrvNum + 'A' - 1, g.rc);
      return -1LL;
   }
   if (pCbSector) *pCbSector = fsa.cbSector;
   return   (LONGLONG)fsa.cbSector * (LONGLONG)fsa.cSectorUnit
          * (LONGLONG)fsa.cUnitAvail;
}
Exemple #14
0
void getDiskLabel(unsigned char drive, char *label)
{
 #ifdef __OS2__
  struct {
    ULONG volID;
    BYTE  labellen;
    char  label[40];
  } buf;
  if (DosQueryFSInfo(drive,2,&buf,sizeof(buf))!=0) strcpy(label,"");
    else strncpy(label,buf.label,40);
 #else
  struct ffblk ffblk;
  char a[10] = " :\*.*";
  a[0]=drive+64;
  if (!findfirst(a,&ffblk,FA_LABEL)) {
   strcpy(label,ffblk.ff_name);
  } else {
   strcpy(label,"");
  }
 #endif
}
VOID QueryDiskSpace (ULONG drvNum, PULONG totalSpace,
		     PULONG allocated, PULONG available)
{
FSALLOCATE fsAllocate;

DosError (FERR_DISABLEHARDERR);

if (!DosQueryFSInfo (drvNum, FSIL_ALLOC, &fsAllocate, sizeof(FSALLOCATE)))
   {
   *totalSpace =
	    fsAllocate.cSectorUnit * fsAllocate.cUnit * fsAllocate.cbSector;
   *available  =
	    fsAllocate.cSectorUnit * fsAllocate.cUnitAvail * fsAllocate.cbSector;
   *allocated  = *totalSpace - *available;
   }
else
   *totalSpace = *allocated = *available  = 0L;

DosError (FERR_ENABLEHARDERR);
return;
}
//----------------------------------
//  'User Function' private: ScanDrives
//----------------------------------
void PrjPath::ScanDrives(void)
{
    char s[MAXPATHSIZE];
    // GET DRIVES
    m_Drives->Clear();
    m_Drives->ClearList();
    char max;
    DosError(2);        // NO ANOYING  POPUP ERROR DRIVE NOT READY !!
    for(int drv = 'C'; drv<=HiDrive; drv++)
    {
        struct
        {
            unsigned long serno;
            unsigned char vollen;
            char volume[MAXPATHSIZE];
        }infobuf;
        infobuf.vollen = 0;
        infobuf.volume[0] = NULL;
        int rc = DosQueryFSInfo(drv-'@',2,&infobuf,sizeof(infobuf));
        if(rc == 0 || infobuf.vollen > 0 )
        {
            max = drv;
            sprintf(s,"%c:  [%s]",drv,infobuf.volume);
            m_Drives->AddString(s);
        }
    }
    DosError(1);    // Allow Popup excecptions again !!!
    HiDrive = max;  // Next Time Scan C-HiDrive skipping CD-ROMS
    sprintf(s,"C: - %c:",HiDrive);
    //
    // select current Disk Drive
    char s2[2+1];
    strncpy(s2,m_origdir,2); s2[2]=NULL;    // s2="x:"
    strupr(s2);
    int i = m_Drives->FindString(s2,-1);
    m_Drives->SetSelIndex(i);
    SetDlgItemText(ID_HIDRIVE,s);
    //
    DoDirectories();
}
VOID QueryDiskSpace (ULONG ulDriveNumber, PULONG pulTotalSpace,
                     PULONG pulAllocated, PULONG pulAvailable)
{
    FSALLOCATE fsAllocate;

    DosError (FERR_DISABLEHARDERR);

    if (!DosQueryFSInfo (ulDriveNumber, FSIL_ALLOC, &fsAllocate, sizeof(FSALLOCATE)))
    {
        *pulTotalSpace =
            fsAllocate.cSectorUnit * fsAllocate.cUnit * fsAllocate.cbSector;
        *pulAvailable  =
            fsAllocate.cSectorUnit * fsAllocate.cUnitAvail * fsAllocate.cbSector;
        *pulAllocated  = *pulTotalSpace - *pulAvailable;
    }
    else
        *pulTotalSpace = *pulAllocated = *pulAvailable  = 0L;

    DosError (FERR_ENABLEHARDERR);

    return;
}
Exemple #18
0
static APIRET SetDriveText (ULONG ulD,char *s) {

  FSALLOCATE   fsa;
  ULONG        sl,sh;
  APIRET       rc;
  char         ss[8],mb;

  rc = DosQueryFSInfo(ulD,
                      FSIL_ALLOC,
                      &fsa,
                      sizeof(FSALLOCATE));
  if(!rc) {
    mb = MakeNumber(fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector),
                    &sh,
                    &sl);
    *ss = 0;
    if(sl)
      sprintf(ss,
              ".%02lu",
              sl);
    sprintf(s,
            " %c:  %lu%s%cb free (%lu%%) ",
            (char)(ulD + '@'),
            sh,
            ss,
            mb,
            ((fsa.cUnit &&
              fsa.cUnitAvail) ?
              (fsa.cUnitAvail * 100) / fsa.cUnit :
              0));
  }
  else
    sprintf(s,
            " %c:  SYS%04lu",
            (char)(ulD + '@'),
            rc);
  return rc;
}
Exemple #19
0
void DOS_Drive_Cache::SetBaseDir(const char* baseDir) {
	Bit16u id;
	strcpy(basePath,baseDir);
	if (OpenDir(baseDir,id)) {
		char* result = 0;
		ReadDir(id,result);
	};
	// Get Volume Label
#if defined (WIN32) || defined (OS2)
	bool cdrom = false;
	char labellocal[256]={ 0 };
	char drive[4] = "C:\\";
	drive[0] = basePath[0];
#if defined (WIN32)
	if (GetVolumeInformation(drive,labellocal,256,NULL,NULL,NULL,NULL,0)) {
	UINT test = GetDriveType(drive);
	if(test == DRIVE_CDROM) cdrom = true;
#else // OS2
	//TODO determine wether cdrom or not!
	FSINFO fsinfo;
	ULONG drivenumber = drive[0];
	if (drivenumber > 26) { // drive letter was lowercase
		drivenumber = drive[0] - 'a' + 1;
	}
	APIRET rc = DosQueryFSInfo(drivenumber, FSIL_VOLSER, &fsinfo, sizeof(FSINFO));
	if (rc == NO_ERROR) {
#endif
		/* Set label and allow being updated */
		SetLabel(labellocal,cdrom,true);
	}
#endif
}

void DOS_Drive_Cache::ExpandName(char* path) {
	strcpy(path,GetExpandName(path));
}
Exemple #20
0
Int64 GetFreeDisk(const char *FileName)
{
#ifdef _WIN_32
  char Root[NM];
  GetPathRoot(FileName,Root);

  typedef BOOL (WINAPI *GETDISKFREESPACEEX)(
    LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER
   );
  static GETDISKFREESPACEEX pGetDiskFreeSpaceEx=NULL;

  if (pGetDiskFreeSpaceEx==NULL)
  {
    HMODULE hKernel=GetModuleHandle("kernel32.dll");
    if (hKernel!=NULL)
      pGetDiskFreeSpaceEx=(GETDISKFREESPACEEX)GetProcAddress(hKernel,"GetDiskFreeSpaceExA");
  }
  if (pGetDiskFreeSpaceEx!=NULL)
  {
    GetFilePath(FileName,Root);
    ULARGE_INTEGER uiTotalSize,uiTotalFree,uiUserFree;
    uiUserFree.u.LowPart=uiUserFree.u.HighPart=0;
    if (pGetDiskFreeSpaceEx(*Root ? Root:NULL,&uiUserFree,&uiTotalSize,&uiTotalFree) &&
        uiUserFree.u.HighPart<=uiTotalFree.u.HighPart)
      return(int32to64(uiUserFree.u.HighPart,uiUserFree.u.LowPart));
  }

  DWORD SectorsPerCluster,BytesPerSector,FreeClusters,TotalClusters;
  if (!GetDiskFreeSpace(*Root ? Root:NULL,&SectorsPerCluster,&BytesPerSector,&FreeClusters,&TotalClusters))
    return(1457664);
  Int64 FreeSize=SectorsPerCluster*BytesPerSector;
  FreeSize=FreeSize*FreeClusters;
  return(FreeSize);
#elif defined(_BEOS)
  char Root[NM];
  GetFilePath(FileName,Root);
  dev_t Dev=dev_for_path(*Root ? Root:".");
  if (Dev<0)
    return(1457664);
  fs_info Info;
  if (fs_stat_dev(Dev,&Info)!=0)
    return(1457664);
  Int64 FreeSize=Info.block_size;
  FreeSize=FreeSize*Info.free_blocks;
  return(FreeSize);
#elif defined(_UNIX)
  return(1457664);
#elif defined(_EMX)
  int Drive=(!isalpha(FileName[0]) || FileName[1]!=':') ? 0:toupper(FileName[0])-'A'+1;
  if (_osmode == OS2_MODE)
  {
    FSALLOCATE fsa;
    if (DosQueryFSInfo(Drive,1,&fsa,sizeof(fsa))!=0)
      return(1457664);
    Int64 FreeSize=fsa.cSectorUnit*fsa.cbSector;
    FreeSize=FreeSize*fsa.cUnitAvail;
    return(FreeSize);
  }
  else
  {
    union REGS regs,outregs;
    memset(&regs,0,sizeof(regs));
    regs.h.ah=0x36;
    regs.h.dl=Drive;
    _int86 (0x21,&regs,&outregs);
    if (outregs.x.ax==0xffff)
      return(1457664);
    Int64 FreeSize=outregs.x.ax*outregs.x.cx;
    FreeSize=FreeSize*outregs.x.bx;
    return(FreeSize);
  }
#else
  #define DISABLEAUTODETECT
  return(1457664);
#endif
}
int main (int argc, char *argv[])
{
  char logText[CCHMAXPATH];
  short a;
  FILE *file;
  ULONG fl;
  HWND hwndClient;
  char text[CCHMAXPATH+10];
  char title[CCHMAXPATH];

  /* Create a copy of the args */
  /* argv[0]: progname
   * argv[1]: installdir of Audio-CD-Creator
   * argv[2]: foldername
   * argv[3]: imagename
   * argv[4]: Parameter file
   */
  ULONG ulDriveNum=0;
  ULONG ulDriveMap=0;
  APIRET rc;
  int i;

  rc=DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
  if(rc!=NO_ERROR) {
    printf("Error\n");
    exit(1);
  }
  printf("Current disk: %c:\n",'A'+ulDriveNum-1);
  printf("Drive map:\n");
  printf("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\n");

  for(i=0;i<26;i++) {
    printf(( (ulDriveMap << (31-i)) >>31) ? "y ": "- ");
  }
  printf("\n\n");

  DosError(FERR_DISABLEHARDERR);
  for(i=2;i<26;i++) {
    if(( (ulDriveMap << (31-i)) >>31)) {
      char chrDrive[3]="A:";
      BYTE fsqBuf2[sizeof(FSQBUFFER2)+3*CCHMAXPATH]={0};
      PFSQBUFFER2 pfsqBuf2=(PFSQBUFFER2) &fsqBuf2;
      ULONG ulLength;
      /* Get FS */
      chrDrive[0]='A'+i;
      ulLength=sizeof(fsqBuf2);
      rc=DosQueryFSAttach(chrDrive,0L,FSAIL_QUERYNAME, (PFSQBUFFER2)&fsqBuf2, &ulLength);
      if(DosQueryFSAttach(chrDrive,0L,FSAIL_QUERYNAME, (PFSQBUFFER2)&fsqBuf2, &ulLength)==NO_ERROR) {
        if(!strcmp(pfsqBuf2->szName+pfsqBuf2->cbName+1,"ISOFS")) {
          FSINFO fsInfo;
          rc=DosQueryFSInfo(i+1, FSIL_VOLSER, &fsInfo,sizeof(fsInfo));
          printf("%s %s %d %s\n",chrDrive, pfsqBuf2->szName+pfsqBuf2->cbName+1, i+1, fsInfo.vol.szVolLabel); 
        }
      }
      else
        printf("%s %s\n",chrDrive, "---"); 
    }
  }
  DosError(FERR_ENABLEHARDERR);
    
  printf("\n\nDone");
  
  return 0;
}
Exemple #22
0
double hb_fsDiskSpace( const char * pszPath, HB_USHORT uiType )
{
   char szPathBuf[ 2 ];
   double dSpace = 0.0;

   if( uiType > HB_DISK_TOTAL )
      uiType = HB_DISK_AVAIL;

   if( ! pszPath )
   {
      szPathBuf[ 0 ] = HB_OS_PATH_DELIM_CHR;
      szPathBuf[ 1 ] = '\0';
      pszPath = szPathBuf;
   }

#if defined( HB_OS_WIN )
   {
      LPCTSTR lpPath;
      LPTSTR lpFree;

      lpPath = HB_FSNAMECONV( pszPath, &lpFree );

      {
         UINT uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS );
         HB_BOOL fResult;

#if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 )
         /* NOTE: We need to call this function dynamically to maintain support
                  Win95 first edition. It was introduced in Win95B (aka OSR2) [vszakats] */
         typedef BOOL ( WINAPI * P_GDFSE )( LPCTSTR, PULARGE_INTEGER,
                                            PULARGE_INTEGER, PULARGE_INTEGER );
         static P_GDFSE s_pGetDiskFreeSpaceEx = NULL;
         static HB_BOOL s_fInit = HB_FALSE;

         if( ! s_fInit )
         {
            HMODULE hModule = GetModuleHandle( HB_WINAPI_KERNEL32_DLL() );
            if( hModule )
               s_pGetDiskFreeSpaceEx = ( P_GDFSE )
                  HB_WINAPI_GETPROCADDRESST( hModule, "GetDiskFreeSpaceEx" );
            s_fInit = HB_TRUE;
         }

         if( ! s_pGetDiskFreeSpaceEx )
         {
            DWORD dwSectorsPerCluster;
            DWORD dwBytesPerSector;
            DWORD dwNumberOfFreeClusters;
            DWORD dwTotalNumberOfClusters;

            fResult = GetDiskFreeSpace( lpPath,
                                        &dwSectorsPerCluster,
                                        &dwBytesPerSector,
                                        &dwNumberOfFreeClusters,
                                        &dwTotalNumberOfClusters ) ? HB_TRUE : HB_FALSE;
            hb_fsSetIOError( fResult, 0 );

            if( fResult )
            {
               switch( uiType )
               {
                  case HB_DISK_AVAIL:
                  case HB_DISK_FREE:
                     dSpace = ( double ) dwNumberOfFreeClusters *
                              ( double ) dwSectorsPerCluster *
                              ( double ) dwBytesPerSector;
                     break;

                  case HB_DISK_USED:
                  case HB_DISK_TOTAL:
                     dSpace = ( double ) dwTotalNumberOfClusters *
                              ( double ) dwSectorsPerCluster *
                              ( double ) dwBytesPerSector;

                     if( uiType == HB_DISK_USED )
                        dSpace -= ( double ) dwNumberOfFreeClusters *
                                  ( double ) dwSectorsPerCluster *
                                  ( double ) dwBytesPerSector;
                     break;
               }
            }
         }
         else
#endif
         {
#if defined( _MSC_VER ) || defined( __LCC__ ) || \
    ( defined( __GNUC__ ) && ! defined( __RSXNT__ ) )

#  define HB_GET_LARGE_UINT( v )  ( ( double ) (v).LowPart + \
                                    ( double ) (v).HighPart * \
                                    ( ( ( double ) 0xFFFFFFFF ) + 1 ) )

#else
   /* NOTE: Borland doesn't seem to deal with the un-named
            struct that is part of ULARGE_INTEGER
            [pt] */
#  define HB_GET_LARGE_UINT( v )  ( ( double ) (v).u.LowPart + \
                                    ( double ) (v).u.HighPart * \
                                    ( ( ( double ) 0xFFFFFFFF ) + 1 ) )
#endif

            ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;

#if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 )
            fResult = s_pGetDiskFreeSpaceEx( lpPath,
                                             ( PULARGE_INTEGER ) &i64FreeBytesToCaller,
                                             ( PULARGE_INTEGER ) &i64TotalBytes,
                                             ( PULARGE_INTEGER ) &i64FreeBytes );
#else
            fResult = GetDiskFreeSpaceEx( lpPath,
                                          ( PULARGE_INTEGER ) &i64FreeBytesToCaller,
                                          ( PULARGE_INTEGER ) &i64TotalBytes,
                                          ( PULARGE_INTEGER ) &i64FreeBytes );
#endif
            hb_fsSetIOError( fResult, 0 );

            if( fResult )
            {
               switch( uiType )
               {
                  case HB_DISK_AVAIL:
                     dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller );
                     break;

                  case HB_DISK_FREE:
                     dSpace = HB_GET_LARGE_UINT( i64FreeBytes );
                     break;

                  case HB_DISK_TOTAL:
                     dSpace = HB_GET_LARGE_UINT( i64TotalBytes );
                     break;

                  case HB_DISK_USED:
                     dSpace = HB_GET_LARGE_UINT( i64TotalBytes ) -
                              HB_GET_LARGE_UINT( i64FreeBytes );
                     break;
               }
            }
         }
         SetErrorMode( uiErrMode );
      }
      if( lpFree )
         hb_xfree( lpFree );
   }
#elif defined( HB_OS_DOS ) || defined( HB_OS_OS2 )
   {
      HB_USHORT uiDrive;

      uiDrive = pszPath == NULL || pszPath[ 0 ] == 0 ||
                pszPath[ 1 ] != HB_OS_DRIVE_DELIM_CHR ? 0 :
                ( pszPath[ 0 ] >= 'A' && pszPath[ 0 ] <= 'Z' ?
                  pszPath[ 0 ] - 'A' + 1 :
                ( pszPath[ 0 ] >= 'a' && pszPath[ 0 ] <= 'z' ?
                  pszPath[ 0 ] - 'a' + 1 : 0 ) );
#if defined( HB_OS_DOS )
      for( ;; )
      {
         union REGS regs;

         regs.HB_XREGS.dx = uiDrive;
         regs.h.ah = 0x36;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.HB_XREGS.ax != 0xFFFF )
         {
            HB_USHORT uiClusterTotal  = regs.HB_XREGS.dx;
            HB_USHORT uiClusterFree   = regs.HB_XREGS.bx;
            HB_USHORT uiSecPerCluster = regs.HB_XREGS.ax;
            HB_USHORT uiSectorSize    = regs.HB_XREGS.cx;

            switch( uiType )
            {
               case HB_DISK_AVAIL:
               case HB_DISK_FREE:
                  dSpace = ( double ) uiClusterFree *
                           ( double ) uiSecPerCluster *
                           ( double ) uiSectorSize;
                  break;

               case HB_DISK_USED:
               case HB_DISK_TOTAL:
                  dSpace = ( double ) uiClusterTotal *
                           ( double ) uiSecPerCluster *
                           ( double ) uiSectorSize;

                  if( uiType == HB_DISK_USED )
                     dSpace -= ( double ) uiClusterFree *
                               ( double ) uiSecPerCluster *
                               ( double ) uiSectorSize;
                  break;
            }
         }
         else
         {
            if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) == E_RETRY )
               continue;
         }
         break;
      }
#else /* HB_OS_OS2 */
      {
         struct _FSALLOCATE fsa;
         APIRET rc;
         /* Query level 1 info from filesystem */
         while( ( rc = DosQueryFSInfo( uiDrive, 1, &fsa, sizeof( fsa ) ) ) != NO_ERROR )
         {
            if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) != E_RETRY )
               break;
         }

         hb_fsSetError( ( HB_ERRCODE ) rc );

         if( rc == NO_ERROR )
         {
            switch( uiType )
            {
               case HB_DISK_AVAIL:
               case HB_DISK_FREE:
                  dSpace = ( double ) fsa.cUnitAvail *
                           ( double ) fsa.cSectorUnit *
                           ( double ) fsa.cbSector;
                  break;

               case HB_DISK_USED:
               case HB_DISK_TOTAL:
                  dSpace = ( double ) fsa.cUnit *
                           ( double ) fsa.cSectorUnit *
                           ( double ) fsa.cbSector;

                  if( uiType == HB_DISK_USED )
                     dSpace -= ( double ) fsa.cUnitAvail *
                               ( double ) fsa.cSectorUnit *
                               ( double ) fsa.cbSector;
                  break;
            }
         }
      }
#endif
   }

#elif defined( HB_OS_UNIX ) && \
      !( defined( __WATCOMC__ ) || defined( __CEGCC__ ) || defined( HB_OS_SYMBIAN ) )
   {
#if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \
    defined( HB_OS_VXWORKS )
      struct statfs sf;
#else
      struct statvfs sf;
#endif
      char * pszFree;

      pszPath = hb_fsNameConv( pszPath, &pszFree );

#if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \
    defined( HB_OS_VXWORKS )
      if( statfs( pszPath, &sf ) == 0 )
#else
      if( statvfs( pszPath, &sf ) == 0 )
#endif
      {
         switch( uiType )
         {
            case HB_DISK_AVAIL:
               dSpace = ( double ) sf.f_bavail * ( double ) sf.f_bsize;
               break;

            case HB_DISK_FREE:
               dSpace = ( double ) sf.f_bfree * ( double ) sf.f_bsize;
               break;

            case HB_DISK_USED:
               dSpace = ( double ) ( sf.f_blocks - sf.f_bfree ) *
                        ( double ) sf.f_bsize;
               break;

            case HB_DISK_TOTAL:
               dSpace = ( double ) sf.f_blocks * ( double ) sf.f_bsize;
               break;
         }
         hb_fsSetIOError( HB_TRUE, 0 );
      }
      else
         hb_fsSetIOError( HB_FALSE, 0 );

      if( pszFree )
         hb_xfree( pszFree );
   }
#else
   {
      int iTODO;

      HB_SYMBOL_UNUSED( uiType );
   }
#endif

   return dSpace;
}
/* This Proc handles the ISO image mounting */
MRESULT EXPENTRY unmountIsoDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
  char text[CCHMAXPATH];
  char title[CCHMAXPATH];

  ULONG rc;
  SWCNTRL swctl;
  PID pid;

  switch (msg)
    {      
    case WM_INITDLG:
      {
        BOOL bDone=FALSE;
        int i;

        writeLog("Initializing dialog...\n");  
        
        /* Add switch entry */
        memset(&swctl,0,sizeof(swctl));
        WinQueryWindowProcess(hwnd,&pid,NULL);
        swctl.hwnd=hwnd;
        swctl.uchVisibility=SWL_VISIBLE;
        swctl.idProcess=pid;
        swctl.bProgType=PROG_DEFAULT;
        swctl.fbJump=SWL_JUMPABLE;
        WinAddSwitchEntry(&swctl);
        
        /*sprintf(text,"%d",params[4]);*/ 
        // sprintf(text,"params[1]: %s ",params[1]);
        /* WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, pvSharedMem,
           params[4],
           0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
           WinPostMsg(hwnd,WM_CLOSE,0,0);
           return (MRESULT) TRUE;
           */
        
        /* Get free drive letters */
        if((rc=DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap))!=NO_ERROR)
          WinPostMsg(hwnd,WM_CLOSE,0,0);

        DosError(FERR_DISABLEHARDERR);

        for(i=2;i<26;i++) {
          if(( (ulDriveMap << (31-i)) >>31)) {
            char chrDrive[3]="A:";
            BYTE fsqBuf2[sizeof(FSQBUFFER2)+3*CCHMAXPATH]={0};
            PFSQBUFFER2 pfsqBuf2=(PFSQBUFFER2) &fsqBuf2;
            ULONG ulLength;

            /* Get FS */
            chrDrive[0]='A'+i;
            ulLength=sizeof(fsqBuf2);
            if(DosQueryFSAttach(chrDrive,0L,FSAIL_QUERYNAME, (PFSQBUFFER2)&fsqBuf2, &ulLength)==NO_ERROR) {
              if(!strcmp(pfsqBuf2->szName+pfsqBuf2->cbName+1,"ISOFS")) {
                FSINFO fsInfo;

                if(DosQueryFSInfo(i+1, FSIL_VOLSER, &fsInfo,sizeof(fsInfo))==NO_ERROR)
                  sprintf(text, "%s      (%s)",chrDrive,  fsInfo.vol.szVolLabel); 
                else
                  sprintf(text, "%s      (unknown)",chrDrive); 
                WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_INSERTITEM,MPFROMSHORT(LIT_END),MPFROMP(text));
              }
            }
            else
              printf("%s %s\n",chrDrive, "---"); 
          }
        }
        DosError(FERR_ENABLEHARDERR);

        /* Set dialog font to WarpSans for Warp 4 and above */
        if(cwQueryOSRelease()>=40) {
          WinSetPresParam(hwnd,
                          PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
                          DEFAULT_DIALOG_FONT );
        }
        
        if(!bHaveWindowPos)
          WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ZORDER|SWP_ACTIVATE);
        else
          WinSetWindowPos(hwnd,HWND_TOP,swpWindow.x, swpWindow.y, 0, 0, SWP_MOVE|SWP_ZORDER|SWP_ACTIVATE|SWP_SHOW);
        
        return (MRESULT) TRUE;
      }
    case WM_CLOSE:
      WinQueryWindowPos(hwnd,&swpWindow);
      WinDismissDlg(hwnd,0);
      return FALSE;
    case WM_HELP:
      sendCommand("DISPLAYHELPPANEL=5100");      
      break;
    case WM_COMMAND:
      switch(SHORT1FROMMP(mp1))
        {
        case IDPB_UNMOUNT:
          {
            /* User pressed the Unount button */
            AEFS_DETACH detachparms={0};
            char pszDrive[3]={0};
            HOBJECT hObject;
            SHORT sSelected;
            memset(&detachparms, 0, sizeof(detachparms));

            /* Get the drive letter */
            sSelected=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYSELECTION,
                                             MPFROMSHORT(LIT_FIRST),MPFROMLONG(0L)));
            if(sSelected==LIT_NONE)
              break;

            WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYITEMTEXT,
                       MPFROM2SHORT(sSelected,2),MPFROMP(pszDrive));

            /* Send the attachment request to the FSD. */
            rc = DosFSAttach(
                             //                             (PSZ) "",
                             (PSZ) pszDrive,
                             (PSZ) AEFS_IFS_NAME,
                             &detachparms,
                             sizeof(detachparms),
                             FS_DETACH);
            if (rc) {
              DosBeep(100,400);             
                            
              sprintf(text, "Error while unmounting rc=%d. Make sure there're no open files on the drive.\n", rc);
              WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text,
                             "ISO image unmount error",
                             0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
            }else {
              WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_DELETEITEM,
                         MPFROMSHORT(sSelected),MPFROMLONG(0L));
              sSelected=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYITEMCOUNT,
                                                MPFROMLONG(0L),MPFROMLONG(0L)));
              if(sSelected==0)
                WinEnableWindow(WinWindowFromID(hwnd,IDPB_UNMOUNT), FALSE);
            }

            break;
          }
        case IDPB_UNMOUNTCLOSE:
          WinPostMsg(hwnd,WM_CLOSE,0,0);
          break;
        default:
          break;
        }
      return (MRESULT) FALSE;
    default:
      break;
    }
  return WinDefDlgProc(hwnd, msg, mp1, mp2);    
}
void 
my_statfs (struct my_statfs *myfs_stats, char *path)
{
    PFSALLOCATE pBuf;
    PFSINFO     pFsInfo;
    ULONG       lghBuf;

    ULONG       diskNum = 0;
    ULONG       logical = 0;

    UCHAR       szDeviceName[3] = "A:";
    PBYTE       pszFSDName      = NULL;  /* pointer to FS name            */
    APIRET      rc              = NO_ERROR; /* Return code                */
    BYTE        fsqBuffer[sizeof(FSQBUFFER2) + (3 * CCHMAXPATH)] = {0};
    ULONG       cbBuffer   = sizeof(fsqBuffer);        /* Buffer length) */
    PFSQBUFFER2 pfsqBuffer = (PFSQBUFFER2) fsqBuffer;

    int i, len = 0;

    /* ------------------------------------------------------------------ */

    lghBuf = sizeof(FSALLOCATE);
    pBuf = (PFSALLOCATE) malloc(lghBuf);

    /* Get the free number of Bytes */
    rc = DosQueryFSInfo(0L, FSIL_ALLOC, (PVOID) pBuf, lghBuf);
    /* KBytes available */
    myfs_stats->avail = pBuf->cSectorUnit * pBuf->cUnitAvail * pBuf->cbSector / 1024;
    /* KBytes total */
    myfs_stats->total = pBuf->cSectorUnit * pBuf->cUnit * pBuf->cbSector / 1024; 
    myfs_stats->nfree = pBuf->cUnitAvail;
    myfs_stats->nodes = pBuf->cbSector;

    lghBuf  = sizeof(FSINFO);
    pFsInfo = (PFSINFO) malloc(lghBuf);
    rc      = DosQueryFSInfo(0L, 
                             FSIL_VOLSER, 
                             (PVOID) pFsInfo, 
                             lghBuf);
    /* Get name */
    myfs_stats->device = strdup(pFsInfo->vol.szVolLabel);    /* Label of the Disk */

    /* Get the current disk for DosQueryFSAttach */
    rc = DosQueryCurrentDisk(&diskNum, &logical);

    szDeviceName[0] = (UCHAR) (diskNum + (ULONG) 'A' - 1);
    /* Now get the type of the disk */
    rc = DosQueryFSAttach(szDeviceName, 
                          0L, 
                          FSAIL_QUERYNAME, 
                          pfsqBuffer, 
                          &cbBuffer);

    pszFSDName = pfsqBuffer->szName + pfsqBuffer->cbName + 1;
    myfs_stats->mpoint = strdup(pszFSDName);    /* FAT, HPFS ... */

    myfs_stats->type = pBuf->idFileSystem;
    /* What is about 3 ?*/
    if (myfs_stats->type == 0) {
       myfs_stats->typename = (char *) malloc(11);
       strcpy(myfs_stats->typename, "Local Disk");
    } else {
Exemple #25
0
void RNG_SystemInfoForRNG(void)
{
   unsigned long *plong = 0;
   PTIB ptib;
   PPIB ppib;
   APIRET rc = NO_ERROR;
   DATETIME dt;
   COUNTRYCODE cc = {0};
   COUNTRYINFO ci = {0};
   unsigned long actual = 0;
   char path[_MAX_PATH]="";
   char fullpath[_MAX_PATH]="";
   unsigned long pathlength = sizeof(path);
   FSALLOCATE fsallocate;
   FILESTATUS3 fstatus;
   unsigned long defaultdrive = 0;
   unsigned long logicaldrives = 0;
   unsigned long sysInfo[QSV_MAX] = {0};
   char buffer[20];
   int nBytes = 0;

   nBytes = RNG_GetNoise(buffer, sizeof(buffer));
   RNG_RandomUpdate(buffer, nBytes);
   
   /* allocate memory and use address and memory */
   plong = (unsigned long *)malloc(sizeof(*plong));
   RNG_RandomUpdate(&plong, sizeof(plong));
   RNG_RandomUpdate(plong, sizeof(*plong));
   free(plong);

   /* process info */
   rc = DosGetInfoBlocks(&ptib, &ppib);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(ptib, sizeof(*ptib));
      RNG_RandomUpdate(ppib, sizeof(*ppib));
   }

   /* time */
   rc = DosGetDateTime(&dt);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&dt, sizeof(dt));
   }

   /* country */
   rc = DosQueryCtryInfo(sizeof(ci), &cc, &ci, &actual);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&cc, sizeof(cc));
      RNG_RandomUpdate(&ci, sizeof(ci));
      RNG_RandomUpdate(&actual, sizeof(actual));
   }

   /* current directory */
   rc = DosQueryCurrentDir(0, path, &pathlength);
   strcat(fullpath, "\\");
   strcat(fullpath, path);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(fullpath, strlen(fullpath));
      // path info
      rc = DosQueryPathInfo(fullpath, FIL_STANDARD, &fstatus, sizeof(fstatus));
      if (rc == NO_ERROR)
      {
         RNG_RandomUpdate(&fstatus, sizeof(fstatus));
      }
   }

   /* file system info */
   rc = DosQueryFSInfo(0, FSIL_ALLOC, &fsallocate, sizeof(fsallocate));
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&fsallocate, sizeof(fsallocate));
   }

   /* drive info */
   rc = DosQueryCurrentDisk(&defaultdrive, &logicaldrives);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&defaultdrive, sizeof(defaultdrive));
      RNG_RandomUpdate(&logicaldrives, sizeof(logicaldrives));
   }

   /* system info */
   rc = DosQuerySysInfo(1L, QSV_MAX, (PVOID)&sysInfo, sizeof(ULONG)*QSV_MAX);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&sysInfo, sizeof(sysInfo));
   }

   // now let's do some files
   ReadSystemFiles();

   /* more noise */
   nBytes = RNG_GetNoise(buffer, sizeof(buffer));
   RNG_RandomUpdate(buffer, nBytes);
}
unsigned long SysDriveMap(unsigned char *name,
                           unsigned long numargs,
                           RXSTRING args[],
                           char *queuename,
                           RXSTRING *retstr)
{
    char     temp[MAX];                  /* Entire drive map built here*/
    char     tmpstr[MAX];                /* Single drive entries built */
                                         /* here                       */
    char     buf[256];                   /* Give DosQFSInfo 256 bytes  */
    char     DeviceName[3];              /* Device name or drive letter*/
                                         /* string                     */
    unsigned long    CurDrive;           /* Current drive              */
    unsigned long    DriveMap;           /* Drive map                  */
    unsigned long    Ordinal;            /* Ordinal of entry in name   */
                                         /* list                       */
    unsigned long    FSAInfoLevel;       /* Type of attached FSD data  */
                                         /* required                   */
    unsigned long    DataBufferLen;      /* Buffer length              */
    unsigned long    dnum;               /* Disk num variable          */
    unsigned long    start = 3;          /* Initial disk num           */
    unsigned long    Mode = USED;        /* Query mode USED, FREE,     */
                                         /* LOCAL, etc                 */
    FSQBUFFER2 DataBuffer;               /* Returned data buffer       */
    long     rc;                         /* OS/2 return codes          */

    Ordinal = (unsigned long )0;
    FSAInfoLevel = (unsigned long )1;

    temp[0] = '\0';

#ifdef DLOGGING
    logmessage(__func__);
#endif

    if (numargs > 2) return INVALID_ROUTINE;

    if (numargs >= 1 && args[0].strptr) {
        if ((strlen(args[0].strptr) == 2 &&
            args[0].strptr[1] != ':') ||
            strlen(args[0].strptr) > 2 ||
            strlen(args[0].strptr) == 0 ||
            !isalpha(args[0].strptr[0]))
            return INVALID_ROUTINE;
        start = toupper(args[0].strptr[0])-'A'+1;
    }
                                         /* check the mode             */
    if (numargs == 2 && args[1].strlength != 0) {

        if (!stricmp(args[1].strptr, "FREE")) Mode = FREE;
        else if (!stricmp(args[1].strptr, "USED")) Mode = USED;
        else if (!stricmp(args[1].strptr, "DETACHED")) Mode = DETACHED;
        else if (!stricmp(args[1].strptr, "REMOTE")) Mode = REMOTE;
        else if (!stricmp(args[1].strptr, "LOCAL")) Mode = LOCAL;
        else return INVALID_ROUTINE;
    }
                                         /* perform the query          */
    DosError(0);                         /* Disable Hard-Error Popups  */

    DosQueryCurrentDisk(&CurDrive, &DriveMap);

    DriveMap>>=start-1;                  /* Shift to the first drive   */

    temp[0] = '\0';                      /* Clear temporary buffer     */

    for (dnum = start; dnum <= 26; dnum++) {
        if (!(DriveMap&(unsigned long)1) && Mode == FREE) {
            sprintf(tmpstr, "%c: ", dnum+'A'-1);
            strcat(temp, tmpstr);
        }
                                         /* Hey, we have a used drive  */
        else if ((DriveMap&(unsigned long)1) && Mode == USED) {
            sprintf(tmpstr, "%c: ", dnum+'A'-1);
            strcat(temp, tmpstr);
        }

        else if (DriveMap&(unsigned long)1) {      /* Check specific drive info  */
            sprintf(DeviceName, "%c:", dnum+'A'-1);
            DataBufferLen = sizeof DataBuffer;
            DosQueryFSAttach(DeviceName, Ordinal, FSAInfoLevel, &DataBuffer, &DataBufferLen);
            rc = DosQueryFSInfo(dnum, 2, buf, sizeof(buf));

            if (rc == 67 && DataBuffer.iType == 4 && Mode == DETACHED) {
                                         /* Hey, we have a detached    */
                                         /* drive                      */
                sprintf(tmpstr, "%c: ", dnum+'A'-1);
                strcat(temp, tmpstr);
            } else if (DataBuffer.iType == 4 && Mode == REMOTE) {
                sprintf(tmpstr, "%c: ", dnum+'A'-1);
                strcat(temp, tmpstr);
            } else if (DataBuffer.iType == 3 && Mode == LOCAL) {
                sprintf(tmpstr, "%c: ", dnum+'A'-1);
                strcat(temp, tmpstr);
            }
        }

        DriveMap>>=1;                      /* Shift to the next drive    */
    }

    BUILDRXSTRING(retstr, temp);         /* pass back result           */

    if (retstr->strlength) retstr->strlength--;

    DosError(1);                         /* Enable Hard-Error Popups   */

    return VALID_ROUTINE;                /* no error on call           */
}
Exemple #27
0
MRESULT EXPENTRY SwapProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) {

  static HWND hwndMenu = (HWND)0;

  switch(msg) {
    case WM_CREATE:
      {
        MRESULT mr = PFNWPStatic(hwnd,msg,mp1,mp2);

        WinSendMsg(hwnd,
                   UM_SETUP,
                   MPVOID,
                   MPVOID);
        return mr;
      }

    case WM_MOUSEMOVE:

      break;

    case WM_PRESPARAMCHANGED:
      {
        char *rootname = "SwapMon";

        switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
          case CLOCK_FRAME:
            rootname = "Clock";
            break;
          case HARD_FRAME:
            rootname = "Hard";
            break;
          case CPU_FRAME:
            rootname = "CPU";
            break;
          case CLP_FRAME:
            rootname = "ClipMon";
            break;
          case MEM_FRAME:
            rootname = "Mem";
            break;
          case TSK_FRAME:
            rootname = "Task";
            break;
        }
        PresParamChanged(hwnd,
                         rootname,
                         mp1,
                         mp2);
        PostMsg(hwnd,
                UM_TIMER,
                MPVOID,
                MPVOID);
        PostMsg(hwnd,
                UM_REFRESH,
                MPVOID,
                MPFROMSHORT(TRUE));
      }
      break;

    case WM_APPTERMINATENOTIFY:
      if(WinQueryWindowUShort(hwnd,QWS_ID) == CPU_FRAME) {
        if(!StartCPUThreads())
          WinDestroyWindow(hwnd);
      }
      break;

    case WM_BUTTON1MOTIONSTART:
      {
        POINTL ptl;

        ptl.x = SHORT1FROMMP(mp1);
        ptl.y = SHORT2FROMMP(mp1);
        WinMapWindowPoints(hwnd,
                           HWND_DESKTOP,
                           &ptl,
                           1L);
        PostMsg(hwndConfig,
                UM_SHOWME,
                MPFROM2SHORT((USHORT)ptl.x,(USHORT)ptl.y),
                mp2);
      }
      return MRFROMSHORT(TRUE);

    case WM_BUTTON2MOTIONSTART:
      {
        TRACKINFO TrackInfo;
        SWP       Position;

        memset(&TrackInfo,0,sizeof(TrackInfo));
        TrackInfo.cxBorder   = 1 ;
        TrackInfo.cyBorder   = 1 ;
        TrackInfo.cxGrid     = 1 ;
        TrackInfo.cyGrid     = 1 ;
        TrackInfo.cxKeyboard = 8 ;
        TrackInfo.cyKeyboard = 8 ;
        WinQueryWindowPos(hwnd,&Position);
        TrackInfo.rclTrack.xLeft   = Position.x ;
        TrackInfo.rclTrack.xRight  = Position.x + Position.cx ;
        TrackInfo.rclTrack.yBottom = Position.y ;
        TrackInfo.rclTrack.yTop    = Position.y + Position.cy ;
        WinQueryWindowPos(HWND_DESKTOP,&Position);
        TrackInfo.rclBoundary.xLeft   = Position.x ;
        TrackInfo.rclBoundary.xRight  = Position.x + Position.cx ;
        TrackInfo.rclBoundary.yBottom = Position.y ;
        TrackInfo.rclBoundary.yTop    = Position.y + Position.cy ;
        TrackInfo.ptlMinTrackSize.x = 0 ;
        TrackInfo.ptlMinTrackSize.y = 0 ;
        TrackInfo.ptlMaxTrackSize.x = Position.cx ;
        TrackInfo.ptlMaxTrackSize.y = Position.cy ;
        TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY ;
        if(WinTrackRect(HWND_DESKTOP,
                        (HPS)0,
                        &TrackInfo)) {
          WinSetWindowPos(hwnd,
                          HWND_TOP,
                          TrackInfo.rclTrack.xLeft,
                          TrackInfo.rclTrack.yBottom,
                          0,
                          0,
                          SWP_MOVE);
          switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
            case SWAP_FRAME:
              WinQueryWindowPos(hwnd,&swpSwap);
              SavePrf("SwapSwp",
                      &swpSwap,
                      sizeof(SWP));
              break;
            case CLOCK_FRAME:
              WinQueryWindowPos(hwnd,&swpClock);
              SavePrf("ClockSwp",
                      &swpClock,
                      sizeof(SWP));
              break;
            case HARD_FRAME:
              WinQueryWindowPos(hwnd,&swpHard);
              SavePrf("HardSwp",
                      &swpHard,
                      sizeof(SWP));
              break;
            case CPU_FRAME:
              WinQueryWindowPos(hwnd,&swpCPU);
              SavePrf("CPUSwp",
                      &swpCPU,
                      sizeof(SWP));
              break;
            case CLP_FRAME:
              WinQueryWindowPos(hwnd,&swpClip);
              SavePrf("ClipSwp",
                      &swpClip,
                      sizeof(SWP));
              break;
            case MEM_FRAME:
              WinQueryWindowPos(hwnd,&swpMem);
              SavePrf("MemSwp",
                      &swpMem,
                      sizeof(SWP));
              break;
            case TSK_FRAME:
              WinQueryWindowPos(hwnd,&swpTask);
              SavePrf("TaskSwp",
                      &swpTask,
                      sizeof(SWP));
              break;
          }
        }
      }
      return MRFROMSHORT(TRUE);

    case WM_BUTTON1DOWN:
      WinSetWindowPos(hwnd,
                      HWND_TOP,
                      0,
                      0,
                      0,
                      0,
                      SWP_ZORDER | SWP_DEACTIVATE);
      return MRFROMSHORT(TRUE);

    case WM_BUTTON1DBLCLK:
    case WM_BUTTON1CLICK:
      if((!fNoMonClick &&
          msg == WM_BUTTON1CLICK) ||
         (fNoMonClick &&
          msg == WM_BUTTON1DBLCLK)) {
        switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
          case HARD_FRAME:
            {
              ULONG ulDriveNum,ulDriveMap,x;

              ulDriveMon = min(ulDriveMon,26);
              if(!DosQCurDisk(&ulDriveNum,
                              &ulDriveMap)) {
                for(x = ulDriveMon + 1;x < 26;x++) {
                  if(ulDriveMap & (1 << x)) {
                    ulDriveMon = x;
                    break;
                  }
                }
                if(x >= 26) {
                  for(x = 3;x < ulDriveMon - 1;x++) {
                    if(ulDriveMap & (1 << x)) {
                      ulDriveMon = x;
                      break;
                    }
                  }
                }
                SavePrf("MonDrive",
                        &ulDriveMon,
                        sizeof(ULONG));
              }
              PostMsg(hwnd,
                      UM_TIMER,
                      MPVOID,
                      MPVOID);
            }
            break;

          case CLP_FRAME:
          case MEM_FRAME:
          case TSK_FRAME:
          case SWAP_FRAME:
          case CLOCK_FRAME:
          case CPU_FRAME:
            {
              USHORT cmd = CPU_PULSE;

              switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
                case MEM_FRAME:
                  cmd = CLOCK_CMDLINE;
                  break;
                case TSK_FRAME:
                  cmd = CPU_KILLPROC;
                  break;
                case CLP_FRAME:
                  cmd = CLOCK_CLIPBOARD;
                  break;
                case SWAP_FRAME:
                  cmd = SWAP_LAUNCHPAD;
                  break;
                case CLOCK_FRAME:
                  cmd = CLOCK_SETTINGS;
                  if((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0)
                    cmd = CLOCK_CLOCK;
                  break;
              }
              PostMsg(hwnd,
                      WM_COMMAND,
                      MPFROM2SHORT(cmd,0),
                      MPVOID);
            }
            break;
        }
        return MRFROMSHORT(TRUE);
      }
      else
        PostMsg(hwnd,
                UM_TIMER,
                MPVOID,
                MPVOID);
      break;

    case WM_CONTEXTMENU:
      WinInvalidateRect(hwnd,
                        NULL,
                        FALSE);
      WinSendMsg(hwnd,
                 UM_TIMER,
                 MPVOID,
                 MPVOID);
      WinSetWindowPos(hwnd,
                      HWND_TOP,
                      0,
                      0,
                      0,
                      0,
                      SWP_ZORDER | SWP_DEACTIVATE);
      {
        USHORT id;

        id = WinQueryWindowUShort(hwnd,QWS_ID);
        hwndMenu = WinLoadMenu(HWND_DESKTOP,
                               0,
                               id);
        if(hwndMenu) {

          POINTL   ptl;
          SWP      swp;
          ULONG    ulDriveNum,ulDriveMap,x;
          MENUITEM mi;
          char     s[80];

          SetPresParams(hwndMenu,
                        -1,
                        -1,
                        -1,
                        helvtext);
          switch(id) {
            case CLP_FRAME:
              WinSendMsg(hwndMenu,
                         MM_SETITEMATTR,
                         MPFROM2SHORT(CLP_APPEND,FALSE),
                         MPFROM2SHORT(MIA_CHECKED,
                                      ((fClipAppend) ? MIA_CHECKED : 0)));
              break;

            case HARD_FRAME:
              if(!DosQCurDisk(&ulDriveNum,
                              &ulDriveMap)) {
                mi.iPosition = 0;
                mi.hwndSubMenu = (HWND)0;
                mi.hItem = 0L;
                mi.afStyle = MIS_TEXT | MIS_STATIC;
                mi.afAttribute = MIA_FRAMED;
                mi.id = -1;
                sprintf(s,
                        "Current drive is %c:",
                        (char)(ulDriveMon + '@'));
                WinSendMsg(hwndMenu,
                           MM_INSERTITEM,
                           MPFROMP(&mi),
                           MPFROMP(s));
                mi.iPosition = MIT_END;
                for(x = 2;x < 26;x++) {
                  if(ulDriveMap & (1 << x)) {
                    if(x != ulDriveMon - 1) {
                      mi.afStyle = MIS_TEXT;
                      mi.afAttribute = 0;
                      mi.id = HARD_C + (x - 2);
                      if(fShowFreeInMenus)
                        SetDriveText(x + 1,
                                     s);
                      else
                        sprintf(s,
                                "%c:",
                                (char)(x + 'A'));
                      WinSendMsg(hwndMenu,
                                 MM_INSERTITEM,
                                 MPFROMP(&mi),
                                 MPFROMP(s));
                    }
                  }
                }
              }
              break;

            case CLOCK_FRAME:
              WinEnableMenuItem(hwndMenu,
                                CLOCK_VIRTUAL,
                                fDesktops);
              WinEnableMenuItem(hwndMenu,
                                CLOCK_CLIPBOARD,
                                (ClipHwnd != (HWND)0));
              break;

            default:
              break;
          }
          WinQueryWindowPos(hwnd,
                            &swp);
          ptl.x = SHORT1FROMMP(mp1);
          ptl.y = SHORT2FROMMP(mp1);
          WinMapWindowPoints(hwnd,
                             HWND_DESKTOP,
                             &ptl,
                             1L);
          ptl.y = max(ptl.y,swp.y + swp.cy + 4);
          if(!WinPopupMenu(HWND_DESKTOP,
                           hwnd,
                           hwndMenu,
                           ptl.x - 4,
                           ptl.y - 4,
                           0,
                           PU_HCONSTRAIN | PU_VCONSTRAIN |
                           PU_KEYBOARD   | PU_MOUSEBUTTON1)) {
            WinDestroyWindow(hwndMenu);
            hwndMenu = (HWND)0;
          }
        }
      }
      return MRFROMSHORT(TRUE);

    case WM_MENUEND:
      WinSetFocus(HWND_DESKTOP,
                  HWND_DESKTOP);
      WinDestroyWindow((HWND)mp2);
      if(hwndMenu == (HWND)mp2)
        hwndMenu = (HWND)0;
      return 0;

    case UM_SETUP:
      {
        char *rootname = "SwapMon";

        switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
          case SWAP_FRAME:
            SwapHwnd = hwnd;
            swaptick = 0;
            break;
          case CLOCK_FRAME:
            ClockHwnd = hwnd;
            rootname = "Clock";
            break;
          case TSK_FRAME:
            TaskHwnd = hwnd;
            rootname = "Task";
            break;
          case MEM_FRAME:
            MemHwnd = hwnd;
            rootname = "Mem";
            break;
          case HARD_FRAME:
            HardHwnd = hwnd;
            rootname = "Hard";
            break;
          case CPU_FRAME:
            CPUHwnd = hwnd;
            rootname = "CPU";
            PostMsg(hwnd,
                    UM_REFRESH,
                    MPVOID,
                    MPFROMSHORT(TRUE));
            break;
          case CLP_FRAME:
            ClipMonHwnd = hwnd;
            rootname = "ClipMon";
            PostMsg(hwnd,
                    UM_REFRESH,
                    MPVOID,
                    MPFROMSHORT(TRUE));
            break;
        }
        if(!RestorePresParams(hwnd,rootname))
          SetPresParams(hwnd,
                        RGB_WHITE,
                        RGB_BLACK,
                        RGB_BLACK,
                        helvtext);
      }
      PostMsg(hwnd,
              UM_TIMER,
              MPVOID,
              MPVOID);
      return 0;

    case UM_REFRESH:
      switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
        case CLP_FRAME:
          {
            char  s[] = " Clip: [TtBbMmP] + ",*p;
            ULONG fmt[] = {CF_TEXT,CF_DSPTEXT,
                           CF_BITMAP,CF_DSPBITMAP,
                           CF_METAFILE,CF_DSPMETAFILE,
                           CF_PALETTE,0};
            ULONG x,ret;

            if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) {
              p = s + 8;
              for(x = 0;fmt[x];x++) {
                ret = WinQueryClipbrdData(WinQueryAnchorBlock(hwnd),
                                          fmt[x]);
                if(!ret)
                  *p = '-';
                p++;
              }
              p += 2;
              if(!fClipAppend)
                *p = 0;
              WinCloseClipbrd(WinQueryAnchorBlock(hwnd));
            }
            else
              strcpy(s + 7,
                     "Can't open. ");
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpClip,
                           s);
          }
          break;

        case CPU_FRAME:
          {
            char        s[32];
            ULONG       percent,lastaverage;
            static BOOL lastavgset = 0;

            *s = 0;
            if(mp2) {
              strcpy(s," CPU: -% ");
              if(fAverage)
                strcat(s,"Avg: -%) ");
            }
            else {
              percent = ((MaxCount - (ULONG)mp1) * 100) / MaxCount;
              lastaverage = AveCPU;
              AveCPU = (((AveCPU * NumAveCPU) + percent) /
                        ((ULONG)NumAveCPU + 1));
              NumAveCPU++;
              if(!NumAveCPU)
                NumAveCPU = 65535;
              if(percent != LastPercent ||
                 (AveCPU != lastaverage &&
                  fAverage) ||
                 NumAveCPU == 1 ||
                 lastavgset != fAverage) {
                lastavgset = fAverage;
                LastPercent = percent;
                sprintf(s,
                        " CPU: %lu%% ",
                        percent);
                if(fAverage)
                  sprintf(s + strlen(s),
                          "(Avg: %lu%%) ",
                          AveCPU);
              }
            }
            if(*s)
              SetMonitorSize(hwnd,
                             hwndMenu,
                             &swpCPU,
                             s);
          }
          break;
      }
      return 0;

    case WM_TIMER:
      if(fSwapFloat &&
         !hwndMenu)
        WinSetWindowPos(hwnd,
                        HWND_TOP,
                        0,
                        0,
                        0,
                        0,
                        SWP_ZORDER | SWP_SHOW);
      if(WinQueryWindowUShort(hwnd,QWS_ID) == CLP_FRAME) {
        if(!ClipHwnd)
          WinDestroyWindow(hwnd);
        else
          TakeClipboard();
      }
      return 0;

    case UM_TIMER:
      switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
        case CLP_FRAME:
          ClipMonHwnd = hwnd;
          WinSendMsg(hwnd,
                     WM_TIMER,
                     MPVOID,
                     MPVOID);
          break;

        case CPU_FRAME:
          CPUHwnd = hwnd;
          WinSendMsg(hwnd,
                     WM_TIMER,
                     MPVOID,
                     MPVOID);
          break;

        case HARD_FRAME:
          {
            char s[80];

            HardHwnd = hwnd;
            SetDriveText(ulDriveMon,
                         s);
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpHard,
                           s);
          }
          break;

        case SWAP_FRAME:
          {
            FILEFINDBUF3 ffb;
            ULONG        nm = 1,fl = SWP_SIZE | SWP_SHOW | SWP_MOVE,
                         sh,sl,nh;
            HDIR         hdir = HDIR_CREATE;
            FSALLOCATE   fsa;
            char         s[128],ss[8],sss[8],mb,smb;
            static ULONG lastcbFile = 0;
            static BOOL  warned = FALSE;
            static char  SwapperDat[CCHMAXPATH] = "";

            strcpy(s,
                   " Unable to locate SWAPPER.DAT. ");
            SwapHwnd = hwnd;
            if(!*SwapperDat)
              FindSwapperDat(SwapperDat);
            if(*SwapperDat) {
              DosError(FERR_DISABLEHARDERR);
              if(!DosFindFirst(SwapperDat,
                               &hdir,
                               FILE_NORMAL | FILE_HIDDEN |
                               FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY,
                               &ffb,
                               sizeof(ffb),
                               &nm,
                               FIL_STANDARD)) {
                DosFindClose(hdir);
                if(ffb.cbFile != lastcbFile && lastcbFile)
                  swaptick = 9;
                lastcbFile = ffb.cbFile;
                DosError(FERR_DISABLEHARDERR);
                if(!DosQueryFSInfo(toupper(*SwapperDat) - '@',
                                   FSIL_ALLOC,
                                   &fsa,
                                   sizeof(FSALLOCATE)))
                  nm = fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
                else
                  nm = 0;
                if(nm <= 32768 * 1024) {
                  swaptick = 10;
                  if(!warned) {
                    SetPresParams(hwnd,
                                  RGB_RED,
                                  -1,
                                  -1,
                                  NULL);
                    warned = TRUE;
                    DosBeep(250,15);
                  }
                }
                else if(warned) {
                  PostMsg(hwnd,
                          UM_SETUP,
                          MPVOID,
                          MPVOID);
                  warned = FALSE;
                }
                mb = MakeNumber(nm,
                                &nh,
                                &sl);
                *sss = 0;
                if(sl)
                  sprintf(sss,
                          ".%02lu",
                          sl);
                smb = MakeNumber(ffb.cbFile,
                                 &sh,
                                 &sl);
                *ss = 0;
                if(sl)
                  sprintf(ss,
                          ".%02lu",
                          sl);
                sprintf(s,
                        " Swap: %lu%s%cb ",
                        sh,
                        ss,
                        smb);
                if(fShowSwapFree)
                  sprintf(s + strlen(s),
                          "(%lu%s%cb free) ",
                          nh,
                          sss,
                          mb);
              }
            }
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpSwap,
                           s);
          }
          break;

        case TSK_FRAME:
          {
            PROCESSINFO  *ppi;
            BUFFHEADER   *pbh = NULL;
            MODINFO      *pmi;
            long          numprocs = -1,numthreads = -1;
            char          s[80];

            if(!DosAllocMem((PVOID)&pbh,
                            USHRT_MAX + 4096,
                            PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)) {
              if(!DosQProcStatus(pbh,
                                 USHRT_MAX)) {
                numprocs = numthreads = 0;
                ppi = pbh->ppi;
                while(ppi->ulEndIndicator != PROCESS_END_INDICATOR ) {
                  pmi = pbh->pmi;
                  while(pmi &&
                        ppi->hModRef != pmi->hMod)
                    pmi = pmi->pNext;
                  if(pmi) {
                    numprocs++;
                    numthreads += ppi->usThreadCount;
                  }
                  ppi = (PPROCESSINFO)(ppi->ptiFirst + ppi->usThreadCount);
                }
              }
              DosFreeMem(pbh);
              sprintf(s,
                      " Procs: %ld  Thrds: %ld ",
                      numprocs,
                      numthreads);
              SetMonitorSize(hwnd,
                             hwndMenu,
                             &swpTask,
                             s);
            }
          }
          break;

        case MEM_FRAME:
          {
            ULONG sh,sl,nh,amem;
            char  s[128],ss[8],sss[8],mb,smb;

            strcpy(s,
                   "Can't check virtual memory.");
            MemHwnd = hwnd;
            if(!DosQuerySysInfo(QSV_TOTAVAILMEM,
                                QSV_TOTAVAILMEM,
                                &amem,
                                sizeof(amem))) {
              mb = MakeNumber(amem,
                              &nh,
                              &sl);
              *ss = 0;
              if(sl)
                sprintf(ss,
                        ".%02lu",
                        sl);
              sprintf(s,
                      " VMem: %lu%s%cb ",
                      nh,
                      ss,
                      mb);
            }
            if(fShowPMem) {
              if(!Dos16MemAvail(&amem)) {
                mb = MakeNumber(amem,
                                &nh,
                                &sl);
                *ss = 0;
                if(sl)
                  sprintf(ss,
                          ".%02lu",
                          sl);
                sprintf(s + strlen(s),
                        " PMem: %lu%s%cb ",
                        nh,
                        ss,
                        mb);
              }
            }
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpMem,
                           s);
          }
          break;

        case CLOCK_FRAME:
          {
            char      s[80];
            DATETIME  dt;

            ClockHwnd = hwnd;
            if(!DosGetDateTime(&dt)) {
              sprintf(s,
                      " %0*u:%02u%s ",
                      ((ampm) ? 0 : 2),
                      (dt.hours % ((ampm) ? 12 : 24)) +
                       ((ampm && !(dt.hours % 12)) ? 12 : 0),
                      dt.minutes,
                      ((ampm) ? (dt.hours > 11) ? "pm" : "am" : ""));
              if(showdate)
                sprintf(s + strlen(s),
                        "%02u/%02u ",
                        dt.month,
                        dt.day);
            }
            else
              strcpy(s,"Unknown time");
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpClock,
                           s);
          }
          break;
      }
      return 0;

    case WM_COMMAND:
      {
        BOOL ctrl,shift;

        ctrl = ((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0);
        shift = ((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0);

        switch(SHORT1FROMMP(mp1)) {
          case CLP_CLEAR:
            if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) {
              WinEmptyClipbrd(WinQueryAnchorBlock(hwnd));
              WinCloseClipbrd(WinQueryAnchorBlock(hwnd));
              PostMsg(hwnd,
                      UM_REFRESH,
                      MPVOID,
                      MPVOID);
            }
            break;

          case CLP_APPEND:
            fClipAppend = (fClipAppend) ? FALSE : TRUE;
            SavePrf("ClipAppend",
                    &fClipAppend,
                    sizeof(BOOL));
            PostMsg(hwnd,
                    UM_REFRESH,
                    MPVOID,
                    MPVOID);
            if(ClipSetHwnd)
              PostMsg(ClipSetHwnd,
                      UM_REFRESH,
                      MPVOID,
                      MPVOID);
            break;

          case MSE_HELP:
            ViewHelp(hwnd,
                     "Monitors page");
            break;

          case CPU_PULSE:
            {
              PROGDETAILS pgd;

              WinSetWindowPos(hwnd,
                              HWND_TOP,
                              0,
                              0,
                              0,
                              0,
                              SWP_ACTIVATE | SWP_FOCUSACTIVATE);
              memset(&pgd,
                     0,
                     sizeof(pgd));
              pgd.Length = sizeof(pgd);
              pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER;
              pgd.swpInitial.hwndInsertBehind = HWND_TOP;
              pgd.progt.fbVisible = SHE_VISIBLE;
              pgd.progt.progc = PROG_DEFAULT;
              pgd.pszExecutable = "PULSE.EXE";
              if(WinStartApp(CPUHwnd,
                             &pgd,
                             NULL,
                             NULL,
                             0)) {
                if(CPUHwnd) {
                  closethreads = 1;
                  DosSleep(1);
                  PostMsg(CPUHwnd,
                          UM_REFRESH,
                          MPVOID,
                          MPFROMSHORT(TRUE));
                }
              }
            }
            break;

          case CPU_RESET:
            AveCPU = 0;
            NumAveCPU = 0;
            break;

          case CLOCK_VIRTUAL:
          case CLOCK_SWITCHLIST:
          case CLOCK_CMDLINE:
          case CLOCK_CLIPBOARD:
          case CLOCK_CALCULATOR:
          case HARD_FM2:
          case MSE_FRAME:
            {
              ULONG msg2 = UM_SHOWME;
              MPARAM mp12 = 0,mp22 = 0;
              HWND   hwndP = hwndConfig;

              switch(SHORT1FROMMP(mp1)) {
                case CLOCK_CMDLINE:
                  mp12 = MPFROMLONG(((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0));
                  msg2 = UM_CMDLINE;
                  break;
                case CLOCK_CLIPBOARD:
                  msg2 = UM_CLIPMGR;
                  hwndP = ObjectHwnd3;
                  break;
                case CLOCK_SWITCHLIST:
                  msg2 = UM_SWITCHLIST;
                  break;
                case CLOCK_VIRTUAL:
                  msg2 = UM_VIRTUAL;
                  break;
                case CLOCK_CALCULATOR:
                  msg2 = UM_CALC;
                  break;
                case HARD_FM2:
                  msg2 = UM_STARTWIN;
                  mp12 = MPFROM2SHORT(C_STARTFM2,0);
                  break;
              }
              PostMsg(hwndP,
                      msg2,
                      mp12,
                      mp22);
            }
            break;

          case CLOCK_SETTINGS:
          case CLOCK_CLOCK:
          case SWAP_LAUNCHPAD:
          case SWAP_WARPCENTER:
          case SWAP_CONNECTIONS:
          case SWAP_INFO:
          case SWAP_SETTINGS:
          case SWAP_SYSTEM:
          case SWAP_TEMPS:
          case SWAP_FM2:
          case HARD_OPEN:
          case CVR_COLORPALETTE:
          case CVR_HICOLORPALETTE:
          case CVR_FONTPALETTE:
          case CPU_KILLPROC:
          case CPU_HARDWARE:
            {
              char *p = "<WP_CLOCK>",*pp = defopen;
              char s[8];

              switch(SHORT1FROMMP(mp1)) {
                case HARD_OPEN:
                  sprintf(s,
                          "%c:\\",
                          (char)(ulDriveMon + '@'));
                  p = s;
                  break;
                case SWAP_FM2:
                  p = "<FM3_Folder>";
                  break;
                case SWAP_TEMPS:
                  p = "<WP_TEMPS>";
                  break;
                case SWAP_SYSTEM:
                  p = "<WP_OS2SYS>";
                  break;
                case SWAP_SETTINGS:
                  p = "<WP_CONFIG>";
                  break;
                case SWAP_INFO:
                  p = "<WP_INFO>";
                  break;
                case SWAP_CONNECTIONS:
                  p = "<WP_CONNECTIONSFOLDER>";
                  break;
                case SWAP_WARPCENTER:
                  p = "<WP_WARPCENTER>";
                  break;
                case SWAP_LAUNCHPAD:
                  p = "<WP_LAUNCHPAD>";
                  break;
                case CLOCK_SETTINGS:
                  pp = setopen;
                  break;
                case CVR_COLORPALETTE:
                  p = "<WP_LORESCLRPAL>";
                  break;
                case CVR_HICOLORPALETTE:
                  p = "<WP_HIRESCLRPAL>";
                  break;
                case CVR_FONTPALETTE:
                  p = "<WP_FNTPAL>";
                  break;
                case CPU_KILLPROC:
                  p = "<FM/2_KILLPROC>";
                  break;
                case CPU_HARDWARE:
                  p = "<WP_HWMGR>";
                  break;
              }
              OpenObject(p,
                         pp);
            }
            break;

          case HARD_VDIR:
            {
              PROGDETAILS pgd;
              char        s[36];

              sprintf(s,
                      "/C VDIR.CMD %c:\\",
                      (char)(ulDriveMon + '@'));
              memset(&pgd,
                     0,
                     sizeof(pgd));
              pgd.Length = sizeof(pgd);
              pgd.swpInitial.fl = SWP_MINIMIZE | SWP_ACTIVATE | SWP_ZORDER;
              pgd.swpInitial.hwndInsertBehind = HWND_TOP;
              pgd.progt.fbVisible = SHE_VISIBLE;
              pgd.progt.progc = PROG_DEFAULT;
              pgd.pszExecutable = "CMD.EXE";
              WinStartApp((HWND)0,
                          &pgd,
                          s,
                          NULL,
                          0);
            }
            break;

          case HARD_CHKDSK:
            {
              PROGDETAILS pgd;
              char        s[8];

              WinSetWindowPos(hwnd,
                              HWND_TOP,
                              0,
                              0,
                              0,
                              0,
                              SWP_ACTIVATE | SWP_FOCUSACTIVATE);
              sprintf(s,
                      "%c:",
                      (char)(ulDriveMon + '@'));
              memset(&pgd,
                     0,
                     sizeof(pgd));
              pgd.Length = sizeof(pgd);
              pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER;
              pgd.swpInitial.hwndInsertBehind = HWND_TOP;
              pgd.progt.fbVisible = SHE_VISIBLE;
              pgd.progt.progc = PROG_DEFAULT;
              pgd.pszExecutable = "PMCHKDSK.EXE";
              WinStartApp((HWND)0,
                          &pgd,
                          s,
                          NULL,
                          0);
            }
            break;

          default:
            if(SHORT1FROMMP(mp1) >= HARD_C &&
               SHORT1FROMMP(mp1) <= HARD_C + 24) {
              ulDriveMon = (SHORT1FROMMP(mp1) - HARD_C) + 3;
              PostMsg(hwnd,
                      UM_TIMER,
                      MPVOID,
                      MPVOID);
              if(ctrl)
                PostMsg(hwnd,
                        WM_COMMAND,
                        MPFROM2SHORT(HARD_OPEN,0),
                        MPVOID);
              else if(shift)
                PostMsg(hwnd,
                        WM_COMMAND,
                        MPFROM2SHORT(HARD_VDIR,0),
                        MPVOID);
            }
            break;
        }
      }
      return 0;

    case WM_DESTROY:
      switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
        case SWAP_FRAME:
          SwapHwnd = (HWND)0;
          break;
        case CLOCK_FRAME:
          ClockHwnd = (HWND)0;
          break;
        case HARD_FRAME:
          HardHwnd = (HWND)0;
          break;
        case CPU_FRAME:
          closethreads = 1;
          DosSleep(1);
          CPUHwnd = (HWND)0;
          break;
        case CLP_FRAME:
          ClipMonHwnd = (HWND)0;
          break;
        case MEM_FRAME:
          MemHwnd = (HWND)0;
          break;
        case TSK_FRAME:
          TaskHwnd = (HWND)0;
          break;
      }
      break;
  }
  return PFNWPStatic(hwnd,msg,mp1,mp2);
}
Exemple #28
0
long LocalGetFreeSpace( int drv )
/*******************************/
{
    struct _FSALLOCATE usage;

#ifdef _M_I86
    if( DosQFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) {
#else
    if( DosQueryFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) {
#endif
        return( -1L );
    }
    return( usage.cbSector * usage.cSectorUnit * usage.cUnitAvail );
}

error_handle LocalDateTime( sys_handle fh, int *time, int *date, int set )
/************************************************************************/
{
    struct _FILESTATUS fstatus;
    struct _FDATE *pdate;
    struct _FTIME *ptime;
    unsigned    rc;

    pdate = (struct _FDATE *)date;
    ptime = (struct _FTIME *)time;
    if( set ) {
#ifdef _M_I86
        rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) );
#else
        rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) );
#endif
        if( rc != 0 )
            return( StashErrCode( rc, OP_LOCAL ) );
        fstatus.ftimeLastWrite = *ptime;
        fstatus.fdateLastWrite = *pdate;
        rc = DosSetFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) );
        if( rc != 0 ) {
            return( StashErrCode( rc, OP_LOCAL ) );
        }
    } else {
#ifdef _M_I86
        rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) );
#else
        rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) );
#endif
        if( rc != 0 )
            return( StashErrCode( rc, OP_LOCAL ) );
        *ptime = fstatus.ftimeLastWrite;
        *pdate = fstatus.fdateLastWrite;
    }
    return( 0 );
}

error_handle LocalGetCwd( int drive, char *where )
/************************************************/
{
    APIRET len;

    len = 256;
#ifdef _M_I86
    return( StashErrCode( DosQCurDir( drive, (PBYTE)where, &len ), OP_LOCAL ) );
#else
    return( StashErrCode( DosQueryCurrentDir( drive, (PBYTE)where, &len ), OP_LOCAL ) );
#endif
}