home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Ph 1.1.1 / Lib / fsu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  20.5 KB  |  720 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________________________
  2.  
  3.     fsu.c - File System Utilities.
  4.     
  5.     Copyright © 1988-1991 Northwestern University.
  6.     
  7.     This module exports reusable file system utility routines.
  8.     
  9.     The primary purpose of this module is to permit the use of the new
  10.     System 7 file system specification date type (FSSpec), even on 
  11.     pre-System 7 systems.
  12.     
  13.     All of the code is placed in its own segment named "fsu", except for the
  14.     fsu_Init routine, which is placed in segment fsui.
  15. _____________________________________________________________________*/
  16.  
  17. #pragma load "precompile"
  18. #include "fsu.h"
  19. #include "utl.h"
  20.  
  21. #pragma segment fsu
  22.  
  23. /*______________________________________________________________________
  24.  
  25.     fsu_CheckRFSanity - Check a Resource File's Sanity.
  26.     
  27.     Entry:    fSpec = pointer to file spec.
  28.     
  29.     Exit:        *sane = true if resource fork is sane.
  30.                 function result = error code.
  31.                 
  32.     This routine checks the sanity of a resource file.  The Resource Manager
  33.     does not do error checking, and can bomb or hang if you use it to open
  34.     a damaged resource file.  This routine can be called first to precheck
  35.     the file.
  36.     
  37.     The routine checks the entire resource map.
  38. _____________________________________________________________________*/
  39.  
  40. OSErr fsu_CheckRFSanity (FSSpecPtr fSpec, Boolean *sane)
  41.  
  42. {
  43.     return fsu_HCheckRFSanity(fSpec->vRefNum, fSpec->parID, fSpec->name, 
  44.         sane);
  45. }
  46.  
  47. /*______________________________________________________________________
  48.  
  49.     fsu_FindFolder - Locate Finder Folder.
  50.     
  51.     Entry:    vRefNum = vol ref num.
  52.                 folderType = folder type (kPreferencesFolderType, etc.)
  53.                 createFolder = true to create folder if missing.
  54.                 
  55.     Exit:        foundVRefNum = vol ref num of folder.
  56.                 foundDirID = dir id of folder.
  57.                 function result = error code.
  58.                 
  59.     The vRefNum parameter is currently ignored - the boot disk is
  60.     always used (kOnSystemDisk).
  61.     
  62.     For pre-7.0 systems the folderType and createFolder parameters are
  63.     ignored.  The vol ref num of the boot disk and the directory id of
  64.     the blessed folder are returned.
  65. _____________________________________________________________________*/
  66.  
  67. OSErr fsu_FindFolder (short vRefNum, OSType folderType, Boolean createFolder,
  68.     short *foundVRefNum, long *foundDirID)
  69.     
  70. {
  71. #pragma unused (vRefNum)
  72.  
  73.     if (utl_GestaltFlag(gestaltFindFolderAttr, gestaltFindFolderPresent)) {
  74.         return FindFolder(kOnSystemDisk, folderType, createFolder,
  75.             foundVRefNum, foundDirID);
  76.     } else {
  77.         *foundVRefNum = utl_GetSysVol();
  78.         *foundDirID = utl_GetSysDirID();
  79.         return noErr;
  80.     }
  81. }
  82.  
  83. /*______________________________________________________________________
  84.  
  85.     fsu_FSpCreate - Create File.
  86.     
  87.     Entry:    spec = pointer to file system spec.
  88.                 creator = creator type.
  89.                 fileType = file type.
  90.                 
  91.     Exit:        function result = error code.
  92.     
  93.     The poor man's search path is NOT used.
  94. _____________________________________________________________________*/
  95.  
  96. OSErr fsu_FSpCreate (FSSpecPtr spec, OSType creator, OSType fileType)
  97.  
  98. {
  99.     return fsu_HCreate(spec->vRefNum, spec->parID, spec->name, 
  100.         creator, fileType);
  101. }
  102.  
  103. /*______________________________________________________________________
  104.  
  105.     fsu_FSpCreateResFile - Create Resource File.
  106.     
  107.     Entry:    spec = pointer to file system spec.
  108.                 creator = creator type.
  109.                 fileType = file type.
  110.                 
  111.     Exit:        function result = error code.
  112.     
  113.     The poor man's search path is NOT used.
  114. _____________________________________________________________________*/
  115.  
  116. OSErr fsu_FSpCreateResFile (FSSpecPtr spec, OSType creator, OSType fileType)
  117.     
  118. {
  119.     return fsu_HCreateResFile(spec->vRefNum, spec->parID, spec->name, 
  120.         creator, fileType);
  121. }
  122.  
  123. /*______________________________________________________________________
  124.  
  125.     fsu_FSpDelete - Delete a file.
  126.     
  127.     Entry:    spec = pointer to file system spec.
  128.                 
  129.     Exit:        function result = error code.
  130. _____________________________________________________________________*/
  131.  
  132. OSErr fsu_FSpDelete (FSSpecPtr spec)
  133.  
  134. {
  135.     return fsu_HDelete(spec->vRefNum, spec->parID, spec->name);
  136. }
  137.  
  138. /*______________________________________________________________________
  139.  
  140.     fsu_FSpGetFInfo - Get Finder Info.
  141.     
  142.     Entry:    spec = pointer to file system spec.
  143.                 
  144.     Exit:        fndrInfo = Finder info.
  145.                 function result = error code.
  146. _____________________________________________________________________*/
  147.  
  148. OSErr fsu_FSpGetFInfo (FSSpecPtr spec, FInfo *fndrInfo)
  149.  
  150. {
  151.     return fsu_HGetFInfo(spec->vRefNum, spec->parID, spec->name, fndrInfo);
  152. }    
  153.  
  154. /*______________________________________________________________________
  155.  
  156.     fsu_FSpOpenDF - Open Data Fork.
  157.     
  158.     Entry:    spec = pointer to file system spec.
  159.                 permission = permission.
  160.                 
  161.     Exit:        refNum = opened file refnum.
  162.                 function result = error code.
  163.     
  164.     The poor man's search path is NOT used.
  165. _____________________________________________________________________*/
  166.  
  167. OSErr fsu_FSpOpenDF (FSSpecPtr spec, char permission, short *refNum)
  168.  
  169. {
  170.     return fsu_HOpenDF(spec->vRefNum, spec->parID, spec->name,
  171.         permission, refNum);
  172. }
  173.  
  174. /*______________________________________________________________________
  175.  
  176.     fsu_FSpOpenResFile - Open Resource File.
  177.     
  178.     Entry:    spec = pointer to file system spec.
  179.                 permission = permission.
  180.                 
  181.     Exit:        refNum = opened file refnum.
  182.                 function result = error code.
  183.                 
  184.     The poor man's search path is NOT used.
  185. _____________________________________________________________________*/
  186.  
  187. OSErr fsu_FSpOpenResFile (FSSpecPtr spec, char permission, short *refNum)
  188.  
  189. {
  190.     return fsu_HOpenResFile(spec->vRefNum, spec->parID, spec->name,
  191.         permission, refNum);
  192. }
  193.  
  194. /*______________________________________________________________________
  195.  
  196.     fsu_FSpOpenRF - Open Resource Fork.
  197.     
  198.     Entry:    spec = pointer to file system spec.
  199.                 permission = permission.
  200.                 
  201.     Exit:        refNum = opened file refnum.
  202.                 function result = error code.
  203.     
  204.     The poor man's search path is NOT used.
  205. _____________________________________________________________________*/
  206.  
  207. OSErr fsu_FSpOpenRF (FSSpecPtr spec, char permission, short *refNum)
  208.  
  209. {
  210.     return fsu_HOpenRF(spec->vRefNum, spec->parID, spec->name,
  211.         permission, refNum);
  212. }
  213.  
  214. /*______________________________________________________________________
  215.  
  216.     fsu_FSpRstFLock - Unlock a file.
  217.     
  218.     Entry:    spec = pointer to file system spec.
  219.                 
  220.     Exit:        function result = error code.
  221. _____________________________________________________________________*/
  222.  
  223. OSErr fsu_FSpRstFLock (FSSpecPtr spec)
  224.  
  225. {
  226.     return fsu_HRstFLock(spec->vRefNum, spec->parID, spec->name);
  227. }    
  228.  
  229. /*______________________________________________________________________
  230.  
  231.     fsu_FSpSetFInfo - Set Finder Info.
  232.     
  233.     Entry:    spec = pointer to file system spec.
  234.                 fndrInfo = pointer to Finder info.
  235.                 
  236.     Exit:        function result = error code.
  237. _____________________________________________________________________*/
  238.  
  239. OSErr fsu_FSpSetFInfo (FSSpecPtr spec, FInfo *fndrInfo)
  240.  
  241. {
  242.     return fsu_HSetFInfo(spec->vRefNum, spec->parID, spec->name, fndrInfo);
  243. }    
  244.  
  245. /*______________________________________________________________________
  246.  
  247.     fsu_FSpSetFLock - Lock a file.
  248.     
  249.     Entry:    spec = pointer to file system spec.
  250.                 
  251.     Exit:        function result = error code.
  252. _____________________________________________________________________*/
  253.  
  254. OSErr fsu_FSpSetFLock (FSSpecPtr spec)
  255.  
  256. {
  257.     return fsu_HSetFLock(spec->vRefNum, spec->parID, spec->name);
  258. }    
  259.  
  260. /*______________________________________________________________________
  261.  
  262.     fsu_HCheckRFSanity - Check a Resource File's Sanity.
  263.     
  264.     Entry:    vRefNum = vol ref num.
  265.                 dirID = directory id.
  266.                 fileName = file name.
  267.     
  268.     Exit:        *sane = true if resource fork is sane.
  269.                 function result = error code.
  270.                 
  271.     This routine checks the sanity of a resource file.  The Resource Manager
  272.     does not do error checking, and can bomb or hang if you use it to open
  273.     a damaged resource file.  This routine can be called first to precheck
  274.     the file.
  275.     
  276.     The routine checks the entire resource map.
  277. _____________________________________________________________________*/
  278.  
  279. OSErr fsu_HCheckRFSanity (short vRefNum, long dirID, Str255 fileName, 
  280.     Boolean *sane)
  281.  
  282. {
  283.     short                    refNum;            /* file refnum */
  284.     long                    count;            /* number of bytes to read */
  285.     long                    logEOF;            /* logical EOF */
  286.     unsigned char        *map;                /* pointer to resource map */
  287.     unsigned long        dataLWA;            /* offset in file of data end */
  288.     unsigned long        mapLWA;            /* offset in file of map end */
  289.     unsigned short        typeFWA;            /* offset from map begin to type list */
  290.     unsigned short        nameFWA;            /* offset from map begin to name list */
  291.     unsigned char        *pType;            /* pointer into type list */
  292.     unsigned char        *pName;            /* pointer to start of name list */
  293.     unsigned char        *pMapEnd;        /* pointer to end of map */
  294.     short                    nType;            /* number of resource types in map */
  295.     unsigned char        *pTypeEnd;        /* pointer to end of type list */
  296.     short                    nRes;                /* number of resources of given type */
  297.     unsigned short        refFWA;            /* offset from type list to ref list */
  298.     unsigned char        *pRef;            /* pointer into reference list */
  299.     unsigned char        *pRefEnd;        /* pointer to end of reference list */
  300.     unsigned short        resNameFWA;        /* offset from name list to resource name */
  301.     unsigned char        *pResName;        /* pointer to resource name */
  302.     unsigned long        resDataFWA;        /* offset from data begin to resource data */
  303.     Boolean                mapOK;            /* true if map is sane */
  304.     OSErr                    rCode;            /* error code */
  305.     
  306.     struct {
  307.         unsigned long        dataFWA;        /* offset in file of data */
  308.         unsigned long        mapFWA;        /* offset in file of map */
  309.         unsigned long        dataLen;        /* data area length */
  310.         unsigned long        mapLen;        /* map area length */
  311.     } header;
  312.     
  313.     /* Open the resource file. */
  314.     
  315.     if (rCode = fsu_HOpenRF(vRefNum, dirID, fileName, fsRdPerm, &refNum)) {
  316.         if (rCode == fnfErr) {
  317.             *sane = true;
  318.             return noErr;
  319.         } else {
  320.             return rCode;
  321.         }
  322.     }
  323.     
  324.     /* Get the logical eof of the file. */
  325.     
  326.     if (rCode = GetEOF(refNum, &logEOF)) return rCode;
  327.     if (!logEOF) {
  328.         *sane = true;
  329.         if (rCode = FSClose(refNum)) return rCode;
  330.         return noErr;
  331.     }
  332.     
  333.     /* Read and validate the resource header. */
  334.     
  335.     count = 16;
  336.     if (rCode = FSRead(refNum, &count, (Ptr)&header)) {
  337.         FSClose(refNum);
  338.         return rCode;
  339.     }
  340.     dataLWA = header.dataFWA + header.dataLen;
  341.     mapLWA = header.mapFWA + header.mapLen;
  342.     mapOK = count == 16 && header.mapLen > 28 &&
  343.         header.dataFWA < 0x01000000 && header.mapFWA < 0x01000000 &&
  344.         dataLWA <= logEOF && mapLWA <= logEOF &&
  345.         (dataLWA <= header.mapFWA || mapLWA <= header.dataFWA);
  346.         
  347.     /* Read the resource map. */
  348.     
  349.     map = nil;
  350.     if (mapOK) {
  351.         map = (unsigned char*)NewPtr(header.mapLen);
  352.         if (!(rCode = SetFPos(refNum, fsFromStart, header.mapFWA))) {
  353.             count = header.mapLen;
  354.             rCode = FSRead(refNum, &count, map);
  355.         }
  356.     }
  357.     
  358.     /* Verify the type list and name list offsets. */
  359.     
  360.     if (!rCode) {
  361.         typeFWA = *(unsigned short*)(map+24);
  362.         nameFWA = *(unsigned short*)(map+26);
  363.         mapOK = typeFWA == 28 && nameFWA >= typeFWA && nameFWA <= header.mapLen &&
  364.             !(typeFWA & 1) && !(nameFWA & 1);
  365.     }
  366.     
  367.     /* Verify the type list, reference lists, and name list. */
  368.     
  369.     if (mapOK) {
  370.         pType = map + typeFWA;
  371.         pName = map + nameFWA;
  372.         pMapEnd = map + header.mapLen;
  373.         nType = *(short*)pType + 1;
  374.         pType += 2;
  375.         pTypeEnd = pType + (nType<<3);
  376.         if (mapOK = pTypeEnd <= pMapEnd) {
  377.             while (pType < pTypeEnd) {
  378.                 nRes = *(short*)(pType+4) + 1;
  379.                 refFWA = *(unsigned short*)(pType+6);
  380.                 pRef = map + typeFWA + refFWA;
  381.                 pRefEnd = pRef + 12*nRes;
  382.                 if (!(mapOK = pRef >= pTypeEnd && pRef < pName && 
  383.                     !(refFWA & 1))) break;
  384.                 while (pRef < pRefEnd) {
  385.                     resNameFWA = *(unsigned short*)(pRef+2);
  386.                     if (resNameFWA != 0xFFFF) {
  387.                         pResName = pName + resNameFWA;
  388.                         if (!(mapOK = pResName + *pResName < pMapEnd)) break;
  389.                     }
  390.                     resDataFWA = *(unsigned long*)(pRef+4) & 0x00FFFFFF;
  391.                     if (!(mapOK = header.dataFWA + resDataFWA < dataLWA)) break;
  392.                     pRef += 12;
  393.                 }
  394.                 if (!mapOK) break;
  395.                 pType += 8;
  396.             }
  397.         }
  398.     }
  399.     
  400.     /* Dispose of the resource map, close the file and return. */
  401.     
  402.     if (map) DisposPtr((Ptr)map);
  403.     if (!rCode) {
  404.         rCode = FSClose(refNum);
  405.     } else {
  406.         (void) FSClose(refNum);
  407.     }
  408.     *sane = mapOK;
  409.     return rCode;
  410. }
  411.  
  412. /*______________________________________________________________________
  413.  
  414.     fsu_HCreate - Create File.
  415.     
  416.     Entry:    vRefNum = vol ref num.
  417.                 dirID = directory id.
  418.                 fileName = file name.
  419.                 creator = creator type.
  420.                 fileType = file type.
  421.                 
  422.     Exit:        function result = error code.
  423.     
  424.     The poor man's search path is NOT used.
  425. _____________________________________________________________________*/
  426.  
  427. OSErr fsu_HCreate (short vRefNum, long dirID, Str255 fileName, 
  428.     OSType creator, OSType fileType)
  429.  
  430. {
  431.     OSErr                    rCode;            /* result code */
  432.     HParamBlockRec        pBlock;            /* param block */
  433.     FInfo                    fndrInfo;        /* Finder info */
  434.     
  435.     pBlock.fileParam.ioNamePtr = fileName;
  436.     pBlock.fileParam.ioVRefNum = vRefNum;
  437.     pBlock.fileParam.ioDirID = dirID;
  438.     pBlock.fileParam.ioFVersNum = 0;
  439.     if (rCode = PBHCreate(&pBlock, false)) return rCode;
  440.     if (rCode = fsu_HGetFInfo(vRefNum, dirID, fileName, &fndrInfo)) return rCode;
  441.     fndrInfo.fdCreator = creator;
  442.     fndrInfo.fdType = fileType;
  443.     return fsu_HSetFInfo(vRefNum, dirID, fileName, &fndrInfo);
  444. }
  445.  
  446. /*______________________________________________________________________
  447.  
  448.     fsu_HCreateResFile - Create Resource File.
  449.     
  450.     Entry:    vRefNum = vol ref num.
  451.                 dirID = directory id.
  452.                 fileName = file name.
  453.                 creator = creator type.
  454.                 fileType = file type.
  455.                 
  456.     Exit:        function result = error code.
  457.     
  458.     The poor man's search path is NOT used.
  459. _____________________________________________________________________*/
  460.  
  461. OSErr fsu_HCreateResFile (short vRefNum, long dirID, Str255 fileName, 
  462.     OSType creator, OSType fileType)
  463.     
  464. {
  465.     OSErr                    rCode;            /* result code */
  466.     HParamBlockRec        pBlock;            /* PBHCreate param block */
  467.     FInfo                    fndrInfo;        /* Finder info */
  468.     
  469.     /* Note: the following call to PBHCreate is supposed to be
  470.         unnecessary.  See TN 214.  But the 7.0b1 HCreateResFile trap
  471.         doesn't work right - it returns -48 = dupFNErr if a resource
  472.         file with the same name already exists in the system folder.
  473.         See Outside Bug Report JLN8. */
  474.     pBlock.fileParam.ioNamePtr = fileName;
  475.     pBlock.fileParam.ioVRefNum = vRefNum;
  476.     pBlock.fileParam.ioDirID = dirID;
  477.     pBlock.fileParam.ioFVersNum = 0;
  478.     PBHCreate(&pBlock, false);
  479.     HCreateResFile(vRefNum, dirID, fileName);
  480.     if (rCode = ResError()) return rCode;
  481.     if (rCode = fsu_HGetFInfo(vRefNum, dirID, fileName, &fndrInfo)) return rCode;
  482.     fndrInfo.fdCreator = creator;
  483.     fndrInfo.fdType = fileType;
  484.     return fsu_HSetFInfo(vRefNum, dirID, fileName, &fndrInfo);
  485. }
  486.  
  487. /*______________________________________________________________________
  488.  
  489.     fsu_HDelete - Delete a file.
  490.     
  491.     Entry:    vRefNum = vol ref num.
  492.                 dirID = directory id.
  493.                 fileName = file name.
  494.                 
  495.     Exit:        function result = error code.
  496. _____________________________________________________________________*/
  497.  
  498. OSErr fsu_HDelete (short vRefNum, long dirID, Str255 fileName)
  499.  
  500. {
  501.     HParamBlockRec        pBlock;        /* HFS param block */
  502.  
  503.     pBlock.fileParam.ioNamePtr = fileName;
  504.     pBlock.fileParam.ioVRefNum = vRefNum;
  505.     pBlock.fileParam.ioDirID = dirID;
  506.     pBlock.fileParam.ioFVersNum = 0;
  507.     return PBHDelete(&pBlock, false);
  508. }
  509.  
  510. /*______________________________________________________________________
  511.  
  512.     fsu_HGetFInfo - Get Finder Info.
  513.     
  514.     Entry:    vRefNum = vol ref num.
  515.                 dirID = directory id.
  516.                 fileName = file name.
  517.                 
  518.     Exit:        fndrInfo = Finder info.
  519.                 function result = error code.
  520. _____________________________________________________________________*/
  521.  
  522. OSErr fsu_HGetFInfo (short vRefNum, long dirID, Str255 fileName, 
  523.     FInfo *fndrInfo)
  524.  
  525. {
  526.     HParamBlockRec        pBlock;        /* HFS param block */
  527.     OSErr                    rCode;        /* result code */
  528.  
  529.     pBlock.fileParam.ioNamePtr = fileName;
  530.     pBlock.fileParam.ioVRefNum = vRefNum;
  531.     pBlock.fileParam.ioFDirIndex = 0;
  532.     pBlock.fileParam.ioDirID = dirID;
  533.     pBlock.fileParam.ioFVersNum = 0;
  534.     if (rCode = PBHGetFInfo(&pBlock, false)) return rCode;
  535.     *fndrInfo = pBlock.fileParam.ioFlFndrInfo;
  536.     return noErr;
  537. }    
  538.  
  539. /*______________________________________________________________________
  540.  
  541.     fsu_HOpenDF - Open Data Fork.
  542.     
  543.     Entry:    vRefNum = vol ref num.
  544.                 dirID = directory id.
  545.                 fileName = file name.
  546.                 permission = permission.
  547.                 
  548.     Exit:        refNum = opened file refnum.
  549.                 function result = error code.
  550.     
  551.     The poor man's search path is NOT used.
  552. _____________________________________________________________________*/
  553.  
  554. OSErr fsu_HOpenDF (short vRefNum, long dirID, Str255 fileName, 
  555.     char permission, short *refNum)
  556.  
  557. {
  558.     OSErr                    rCode;        /* result code */
  559.     HParamBlockRec        pBlock;        /* HFS param block */
  560.     
  561.     pBlock.ioParam.ioNamePtr = fileName;
  562.     pBlock.ioParam.ioVRefNum = vRefNum;
  563.     pBlock.ioParam.ioPermssn = permission;
  564.     pBlock.ioParam.ioMisc = nil;
  565.     pBlock.fileParam.ioDirID = dirID;
  566.     pBlock.fileParam.ioFVersNum = 0;
  567.     if (rCode = PBHOpen(&pBlock, false)) return rCode;
  568.     *refNum = pBlock.ioParam.ioRefNum;
  569.     return noErr;
  570. }
  571.  
  572. /*______________________________________________________________________
  573.  
  574.     fsu_HOpenResFile - Open Resource File.
  575.     
  576.     Entry:    vRefNum = vol ref num.
  577.                 dirID = directory id.
  578.                 fileName = file name.
  579.                 permission = permission.
  580.                 
  581.     Exit:        refNum = opened file refnum.
  582.                 function result = error code.
  583.                 
  584.     The poor man's search path is NOT used.
  585. _____________________________________________________________________*/
  586.  
  587. OSErr fsu_HOpenResFile (short vRefNum, long dirID, Str255 fileName, 
  588.     char permission, short *refNum)
  589.  
  590. {
  591.     OSErr            rCode;            /* result code */
  592.     FCBPBRec        pBlock;            /* PBGetFCBInfo param block */
  593.  
  594.     *refNum = HOpenResFile(vRefNum, dirID, fileName, permission);
  595.     rCode = ResError();
  596.     /* Note: the following shouldn't be necessary.  But the 7.0b1 HOpenResFile 
  597.         trap doesn't work right - if a resource file with the same name already 
  598.         exists in the system folder it is opened.  See Outside Bug Report 
  599.         JLN8. */
  600.     if (!rCode && !utl_VolIsMFS(vRefNum)) {
  601.         pBlock.ioNamePtr = nil;
  602.         pBlock.ioRefNum = *refNum;
  603.         pBlock.ioFCBIndx = 0;
  604.         rCode = PBGetFCBInfo(&pBlock, false);
  605.         if (!rCode && pBlock.ioFCBParID != dirID) rCode = fnfErr;
  606.         if (rCode) CloseResFile(*refNum);
  607.     }
  608.     return rCode;
  609. }
  610.  
  611. /*______________________________________________________________________
  612.  
  613.     fsu_HOpenRF - Open Resource Fork.
  614.     
  615.     Entry:    vRefNum = vol ref num.
  616.                 dirID = directory id.
  617.                 fileName = file name.
  618.                 permission = permission.
  619.                 
  620.     Exit:        refNum = opened file refnum.
  621.                 function result = error code.
  622.     
  623.     The poor man's search path is NOT used.
  624. _____________________________________________________________________*/
  625.  
  626. OSErr fsu_HOpenRF (short vRefNum, long dirID, Str255 fileName, 
  627.     char permission, short *refNum)
  628.  
  629. {
  630.     OSErr                    rCode;        /* result code */
  631.     HParamBlockRec        pBlock;        /* HFS param block */
  632.     
  633.     pBlock.ioParam.ioNamePtr = fileName;
  634.     pBlock.ioParam.ioVRefNum = vRefNum;
  635.     pBlock.ioParam.ioPermssn = permission;
  636.     pBlock.ioParam.ioMisc = nil;
  637.     pBlock.fileParam.ioDirID = dirID;
  638.     pBlock.ioParam.ioVersNum = 0;
  639.     if (rCode = PBHOpenRF(&pBlock, false)) return rCode;
  640.     *refNum = pBlock.ioParam.ioRefNum;
  641.     return noErr;
  642. }
  643.  
  644. /*______________________________________________________________________
  645.  
  646.     fsu_HRstFLock - Unlock a file.
  647.     
  648.     Entry:    vRefNum = vol ref num.
  649.                 dirID = directory id.
  650.                 fileName = file name.
  651.                 
  652.     Exit:        function result = error code.
  653. _____________________________________________________________________*/
  654.  
  655. OSErr fsu_HRstFLock (short vRefNum, long dirID, Str255 fileName)
  656.  
  657. {
  658.     HParamBlockRec        pBlock;        /* HFS param block */
  659.  
  660.     pBlock.fileParam.ioNamePtr = fileName;
  661.     pBlock.fileParam.ioVRefNum = vRefNum;
  662.     pBlock.fileParam.ioDirID = dirID;
  663.     pBlock.fileParam.ioFVersNum = 0;
  664.     return PBHRstFLock(&pBlock, false);
  665. }    
  666.  
  667. /*______________________________________________________________________
  668.  
  669.     fsu_HSetFInfo - Set Finder Info.
  670.     
  671.     Entry:    vRefNum = vol ref num.
  672.                 dirID = directory id.
  673.                 fileName = file name.
  674.                 fndrInfo = pointer to Finder info.
  675.                 
  676.     Exit:        function result = error code.
  677. _____________________________________________________________________*/
  678.  
  679. OSErr fsu_HSetFInfo (short vRefNum, long dirID, Str255 fileName, 
  680.     FInfo *fndrInfo)
  681.  
  682. {
  683.     HParamBlockRec        pBlock;        /* HFS param block */
  684.     OSErr                    rCode;        /* result code */
  685.  
  686.     pBlock.fileParam.ioNamePtr = fileName;
  687.     pBlock.fileParam.ioVRefNum = vRefNum;
  688.     pBlock.fileParam.ioFDirIndex = 0;
  689.     pBlock.fileParam.ioDirID = dirID;
  690.     pBlock.fileParam.ioFVersNum = 0;
  691.     if (rCode = PBHGetFInfo(&pBlock, false)) return rCode;
  692.     pBlock.fileParam.ioDirID = dirID;
  693.     pBlock.fileParam.ioFlFndrInfo = *fndrInfo;
  694.     pBlock.fileParam.ioFVersNum = 0;
  695.     return PBHSetFInfo(&pBlock, false);
  696. }    
  697.  
  698. /*______________________________________________________________________
  699.  
  700.     fsu_HSetFLock - Lock a file.
  701.     
  702.     Entry:    vRefNum = vol ref num.
  703.                 dirID = directory id.
  704.                 fileName = file name.
  705.                 
  706.     Exit:        function result = error code.
  707. _____________________________________________________________________*/
  708.  
  709. OSErr fsu_HSetFLock (short vRefNum, long dirID, Str255 fileName)
  710.  
  711. {
  712.     HParamBlockRec        pBlock;        /* HFS param block */
  713.  
  714.     pBlock.fileParam.ioNamePtr = fileName;
  715.     pBlock.fileParam.ioVRefNum = vRefNum;
  716.     pBlock.fileParam.ioDirID = dirID;
  717.     pBlock.fileParam.ioFVersNum = 0;
  718.     return PBHSetFLock(&pBlock, false);
  719. }    
  720.