home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / mc454src.zip / mc-4.5.4.src / os2emx / src / mystatfs.c < prev    next >
C/C++ Source or Header  |  1999-01-04  |  4KB  |  135 lines

  1. /* Various utilities - OS/2 versions
  2.    Copyright (C) 1994, 1995, 1996 the Free Software Foundation.
  3.  
  4.    Written 1994, 1995, 1996 by:
  5.    Juan Grigera, Miguel de Icaza, Janne Kukonlehto, Dugan Porter,
  6.    Jakub Jelinek, Mauricio Plaza.
  7.  
  8.    This program is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2 of the License, or
  11.    (at your option) any later version.
  12.    
  13.    This program is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include <config.h>
  23.  
  24. #define INCL_DOS
  25. #define INCL_PM
  26. #define INCL_DOSPROCESS
  27. #define INCL_DOSFILEMGR
  28. #define INCL_DOSDEVICES   /* Device values */
  29. #define INCL_DOSDATETIME
  30. #define INCL_DOSERRORS
  31. #include <os2.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <sys/types.h>
  36. #include <ctype.h>
  37. #include <sys/stat.h>
  38. #include <errno.h>
  39. #include <io.h>
  40. #include <fcntl.h>
  41. #include <signal.h>        /* my_system */
  42. #include <limits.h>        /* INT_MAX */
  43. #include <sys/time.h>        /* select: timeout */
  44. #include <sys/param.h>
  45. #include <sys/stat.h>
  46. #include <stdarg.h>
  47. #include <process.h>
  48. #include "src/fs.h"
  49. #include "src/util.h"
  50. #include "src/dialog.h"
  51.  
  52. #ifndef ENOTEMPTY
  53. #define ENOTEMPTY ERROR_DIR_NOT_EMPTY
  54. #endif
  55.  
  56.  
  57. static char x_device[32],x_mpoint[32];
  58.  
  59. int 
  60. os2_my_statfs (struct my_statfs *myfs_stats, char *path)
  61. {
  62.     PFSALLOCATE pBuf;
  63.     PFSINFO     pFsInfo;
  64.     ULONG       lghBuf;
  65.  
  66.     ULONG       diskNum = 0;
  67.     ULONG       logical = 0;
  68.  
  69.     UCHAR       szDeviceName[3] = "A:";
  70.     PBYTE       pszFSDName      = NULL;  /* pointer to FS name            */
  71.     APIRET      rc              = NO_ERROR; /* Return code                */
  72.     BYTE        fsqBuffer[sizeof(FSQBUFFER2) + (3 * CCHMAXPATH)] = {0};
  73.     ULONG       cbBuffer   = sizeof(fsqBuffer);        /* Buffer length) */
  74.     PFSQBUFFER2 pfsqBuffer = (PFSQBUFFER2) fsqBuffer;
  75.  
  76.     int i, len = 0;
  77.  
  78.     /* ------------------------------------------------------------------ */
  79.     if(strchr(path,'#'))
  80.        { memset(myfs_stats,0,sizeof(*myfs_stats));
  81.          return -1;
  82.        }
  83.     /* ------------------------------------------------------------------ */
  84.  
  85.     lghBuf = sizeof(FSALLOCATE);
  86.     pBuf = (PFSALLOCATE) malloc(lghBuf);
  87.  
  88.     /* Get the free number of Bytes */
  89.     rc = DosQueryFSInfo(0L, FSIL_ALLOC, (PVOID) pBuf, lghBuf);
  90.     /* KBytes available */
  91.     myfs_stats->avail = pBuf->cSectorUnit * pBuf->cUnitAvail * pBuf->cbSector / 1024;
  92.     /* KBytes total */
  93.     myfs_stats->total = pBuf->cSectorUnit * pBuf->cUnit * pBuf->cbSector / 1024; 
  94.     myfs_stats->nfree = pBuf->cUnitAvail;
  95.     myfs_stats->nodes = pBuf->cSectorUnit * pBuf->cUnit; //pBuf->cbSector;
  96.  
  97.     lghBuf  = sizeof(FSINFO);
  98.     pFsInfo = (PFSINFO) malloc(lghBuf);
  99.     rc      = DosQueryFSInfo(0L, 
  100.                              FSIL_VOLSER, 
  101.                              (PVOID) pFsInfo, 
  102.                              lghBuf);
  103.     /* Get name */
  104.     strcpy(x_device,pFsInfo->vol.szVolLabel);    /* Label of the Disk */
  105.     myfs_stats->device = x_device;    
  106.  
  107.     /* Get the current disk for DosQueryFSAttach */
  108.     rc = DosQueryCurrentDisk(&diskNum, &logical);
  109.  
  110.     szDeviceName[0] = (UCHAR) (diskNum + (ULONG) 'A' - 1);
  111.     /* Now get the type of the disk */
  112.     rc = DosQueryFSAttach(szDeviceName, 
  113.                           0L, 
  114.                           FSAIL_QUERYNAME, 
  115.                           pfsqBuffer, 
  116.                           &cbBuffer);
  117.  
  118.     pszFSDName = pfsqBuffer->szName + pfsqBuffer->cbName + 1;
  119.     strcpy(x_mpoint,pszFSDName);    /* FAT, HPFS ... */
  120.     myfs_stats->mpoint = x_mpoint; 
  121.  
  122.     myfs_stats->type = pBuf->idFileSystem;
  123.     /* What is about 3 ?*/
  124.     if (myfs_stats->type == 0) {
  125.        myfs_stats->typename = "Local Disk";
  126.     } else {
  127.        myfs_stats->typename = "Other Device";
  128.     }
  129.  
  130.     free(pBuf);
  131.     free(pFsInfo);
  132.     return 0;
  133. }
  134.  
  135.