home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / packer / infozip / sources / mac.zoo / macfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-01  |  3.6 KB  |  139 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   mac.c
  4.  
  5.   This source file is used by the mac port to support commands not available
  6.   directly on the Mac, i.e. mkdir().
  7.   It also helps determine if we're running on a Mac with HFS and a disk
  8.   formatted for HFS (HFS - Hierarchical File System; compared to its predecessor,
  9.   MFS - Macintosh File System).
  10.   
  11.   ---------------------------------------------------------------------------*/
  12.  
  13. #include "unzip.h"
  14.  
  15. #ifdef MACOS
  16. #ifndef THINK_C
  17. #define FSFCBLen    (*(short *)0x3F6)
  18. #define CtoPstr     c2pstr
  19. #define PtoCstr     p2cstr
  20. #endif
  21.  
  22. static short wAppVRefNum;
  23. static long lAppDirID;
  24. int hfsflag;            /* set if disk has hierarchical file system */
  25.  
  26. static int IsHFSDisk(short wRefNum)
  27. {
  28.     /* get info about the specified volume */
  29.     if (hfsflag == true) {
  30.         HParamBlockRec    hpbr;
  31.         Str255 temp;
  32.         short wErr;
  33.         
  34.         hpbr.volumeParam.ioCompletion = 0;
  35.         hpbr.volumeParam.ioNamePtr = temp;
  36.         hpbr.volumeParam.ioVRefNum = wRefNum;
  37.         hpbr.volumeParam.ioVolIndex = 0;
  38.         wErr = PBHGetVInfo(&hpbr, 0);
  39.  
  40.         if (wErr == noErr && hpbr.volumeParam.ioVFSID == 0
  41.             && hpbr.volumeParam.ioVSigWord == 0x4244) {
  42.                 return true;
  43.         }
  44.     }
  45.  
  46.     return false;
  47. } /* IsHFSDisk */
  48.  
  49. void macfstest(int vrefnum)
  50. {
  51.     Str255 st;
  52.  
  53.     /* is this machine running HFS file system? */
  54.     if (FSFCBLen <= 0) {
  55.         hfsflag = false;
  56.     }
  57.     else
  58.     {
  59.         hfsflag = true;
  60.     }
  61.  
  62.     /* get the file's volume reference number and directory ID */
  63.     if (hfsflag == true) {
  64.         WDPBRec    wdpb;
  65.         OSErr err = noErr;
  66.  
  67.         if (vrefnum != 0) {
  68.             wdpb.ioCompletion = false;
  69.             wdpb.ioNamePtr = st;
  70.             wdpb.ioWDIndex = 0;
  71.             wdpb.ioVRefNum = vrefnum;
  72.             err = PBHGetVol(&wdpb, false);
  73.         
  74.             if (err == noErr) {
  75.                 wAppVRefNum = wdpb.ioWDVRefNum;
  76.                 lAppDirID = wdpb.ioWDDirID;
  77.             }
  78.         }
  79.  
  80.         /* is the disk we're using formatted for HFS? */
  81.         hfsflag = IsHFSDisk(wAppVRefNum);
  82.     }
  83. } /* mactest */
  84.  
  85. int mkdir(char *path)
  86. {
  87.     OSErr    err = -1;
  88.  
  89.     if (path != 0 && strlen(path)<256 && hfsflag == true) {
  90.         HParamBlockRec    hpbr;
  91.         Str255    st;
  92.         short     wVol;
  93.         long      lDirID;
  94.  
  95.         CtoPstr(path);
  96.         hpbr.fileParam.ioNamePtr = st;
  97.         hpbr.fileParam.ioCompletion = NULL;
  98.         err = PBHGetVol((WDPBPtr)&hpbr, false);
  99.         if (err == noErr) {
  100.             wVol = hpbr.wdParam.ioWDVRefNum;
  101.             lDirID = hpbr.wdParam.ioWDDirID;
  102.             hpbr.fileParam.ioCompletion = NULL;
  103.             hpbr.fileParam.ioVRefNum = wVol;
  104.             hpbr.fileParam.ioDirID = lDirID;
  105.             hpbr.fileParam.ioNamePtr = (StringPtr)path;
  106.             err = PBDirCreate(&hpbr, false);
  107.         }    
  108.         PtoCstr(path);
  109.     }
  110.  
  111.     return (int)err;
  112. } /* mkdir */
  113.  
  114. void SetMacVol(char *pch, short wVRefNum)
  115. {
  116.     OSErr err = -1;
  117.  
  118.     if (hfsflag == true) {
  119.         HParamBlockRec  hpbr;
  120.         Str255  st;
  121.  
  122.         hpbr.wdParam.ioCompletion = NULL;
  123.         hpbr.wdParam.ioNamePtr = st;
  124.         hpbr.wdParam.ioVRefNum = wVRefNum;
  125.         hpbr.wdParam.ioWDIndex = 0;
  126.         hpbr.wdParam.ioWDProcID = 0;
  127.         hpbr.wdParam.ioWDVRefNum = 0;
  128.         err = PBGetWDInfo((WDPBPtr)&hpbr, false);
  129.         if (err == noErr) {
  130.             hpbr.wdParam.ioCompletion = NULL;
  131.             hpbr.wdParam.ioNamePtr = NULL;
  132.             err = PBHSetVol((WDPBPtr)&hpbr, false);
  133.         }
  134.     } else {
  135.         err = SetVol((StringPtr)pch, wVRefNum);
  136.     }
  137. } /* SetMacVol */
  138. #endif /* MACOS */
  139.