home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / Catalog Service Access Module / DTS Sample CSAM / Src / CSAM_DSProc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-23  |  5.9 KB  |  203 lines  |  [TEXT/KAHL]

  1. /*                                    CSAM_DSProc.c                                */
  2. /*
  3.  * CSAM_DSProc.c
  4.  * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
  5.  *
  6.  * The CSAM Manager calls this function to process CSAM events.
  7.  * The simple ones are handled immediately, while the complex
  8.  * calls (those that require additional I/O operations) are
  9.  * enqueued via DirParseCommon().
  10.  */
  11. /*
  12.  * Edit history
  13.  * 5/27/93    MM    kDirMapDNodeNumberToPathName call used the wrong
  14.  *                parameter block to return the NULL path.
  15.  * 7/30/93    MM    Redid the kDirMapDNodeNumberToPathName stuff.
  16.  */
  17. #include "DTSSampleCSAM.h"
  18. #ifdef THINK_C
  19. #include <ASM.h>
  20. #endif
  21.  
  22. pascal OSErr
  23. CSAM_DSProc(
  24.         register DTSSampleCSAMInfoPtr    infoPtr,
  25.         register DirParamBlockPtr        pb,
  26.         Boolean                            async
  27.     )
  28. {
  29.         short                        refNum;
  30.         register IconInfoPtr        iconPtr;
  31.         IconInfoPtr                    iconEnd;
  32.         RStringPtr                    parts[1];    /* kDirMapDNodeNumberToPathName    */
  33.         unsigned short                lengthOfPathName;        
  34. #define PACK    (PARAM.mapDNodeNumberToPathNamePB)
  35.  
  36. #ifdef THINK_C
  37.         /*
  38.          * Under Think C, we must save and set up the A4 parameter value.
  39.          * This module must exit at the end of the function.
  40.          */
  41.         asm {
  42.             move.l        a4,-(sp)
  43.             move.l        infoPtr,a0
  44.             move.l        OFFSET(DTSSampleCSAMInfo,originalA4)(a0),a4
  45.         }
  46. #endif                    
  47.         STATUS = noErr;
  48.         /*
  49.          * Look at the request code. Handle the simple requests here:
  50.          * these cannot initiate additional I/O. The hard ones are
  51.          * queued into the main CSAM handler.
  52.          */
  53.         switch (PARAM.header.reqCode) {
  54.         case kDirGetDirectoryIcon:
  55.             LogText('DCmd', "\pkDirGetDirectoryIcon");
  56.             /*
  57.              * Loop through the icon vector to find* the requested value. If the
  58.              * loop succeeds, STATUS will be reset to noErr.
  59.              */
  60.             STATUS = kOCENoSuchIcon;
  61.             iconEnd = &INFO.icons[kNumIcons];
  62.             for (iconPtr = INFO.icons; iconPtr < iconEnd; iconPtr++) {
  63.                 if (iconPtr->iconType == PARAM.getDirectoryIconPB.iconType) {
  64.                     /*
  65.                      * If the user's buffer is too small, return an error and,
  66.                      * en-passant, the correct buffer size.
  67.                      * Otherwise, copy the icon to the user's buffer and return
  68.                      * the number of bytes we copied.
  69.                      */
  70.                     if (PARAM.getDirectoryIconPB.bufferSize < iconPtr->iconLength) {
  71.                         PARAM.getDirectoryIconPB.bufferSize = iconPtr->iconLength;
  72.                         STATUS = kOCEBufferTooSmall;
  73.                     }
  74.                     else {
  75.                         PARAM.getDirectoryIconPB.bufferSize = iconPtr->iconLength;
  76.                         BlockMove(
  77.                             *(iconPtr->iconData),
  78.                             PARAM.getDirectoryIconPB.iconBuffer,
  79.                             iconPtr->iconLength
  80.                         );
  81.                         STATUS = noErr;
  82.                     }
  83.                     break;
  84.                 }
  85.             }
  86.             goto ioComplete;
  87.         case kDirGetDirectoryInfo:
  88.             LogText('DCmd', "\pkDirGetDirectoryInfo");
  89.             PARAM.getDirectoryInfoPB.features = kMyFeatures;
  90.             goto ioComplete;
  91.         case kDirAddDSAMDirectory:
  92.             /*
  93.              * kDirAddDSAMDirectory calls the memory manager, so it
  94.              * must be called synchronously.
  95.              */
  96.             LogText('DCmd', "\pkDirAddDSAMDirectory");
  97.             STATUS = (async) ? paramErr : AddCatalog(infoPtr, pb);
  98.             goto ioComplete;
  99.         case kDirRemoveDirectory:
  100.             /*
  101.              * kDirRemoveDirectory calls the memory manager, so it
  102.              * must be called synchronously.
  103.              */
  104.             LogText('DCmd', "\pkDirRemoveDirectory");
  105.             STATUS = (async) ? paramErr : RemoveCatalog(infoPtr, pb);
  106.             goto ioComplete;
  107.         case kDirMapPathNameToDNodeNumber:
  108.             LogText('DCmd', "\pkDirMapPathNameToDNodeNumber");
  109.             if (PARAM.mapPathNameToDNodeNumberPB.path != NULL)
  110.                 STATUS = kOCENoSuchDNode;
  111.             else {
  112.                 PARAM.mapPathNameToDNodeNumberPB.dNodeNumber = kRootDNodeNumber;
  113.             }
  114.             goto ioComplete;
  115.         case kDirMapDNodeNumberToPathName:
  116.             LogText('DCmd', "\pkMapDNodeNumberToPathName");
  117.             if (PARAM.mapDNodeNumberToPathNamePB.dNodeNumber != kRootDNodeNumber
  118.              && PARAM.mapDNodeNumberToPathNamePB.dNodeNumber != kNULLDNodeNumber)
  119.                 STATUS = kOCENoSuchDNode;
  120.             else {
  121.                 /*
  122.                  * Build a "null" packed path name.
  123.                  */
  124.                 lengthOfPathName = OCEPackedPathNameSize(parts, 0);
  125. #if DEBUG_LOG
  126.                 AuditStatusString(
  127.                     INFO.auditPtr,
  128.                     'DNPn',
  129.                     lengthOfPathName,
  130.                     "\plengthOfPathName"
  131.                 );
  132. #endif
  133.                 /*
  134.                  * Note that this sequence is setup so that you can call
  135.                  * DirMapDNodeNumberToPathName with zero for lengthOfPathName
  136.                  * and NULL for the path, then allocate memory and re-call it
  137.                  * with non-zero, non-NULL, values.
  138.                  */
  139.                 if (lengthOfPathName > PACK.lengthOfPathName) {
  140.                     PACK.lengthOfPathName = lengthOfPathName;
  141.                     STATUS = kOCEMoreData;
  142.                 }
  143.                 else if (PACK.path == NULL)
  144.                     STATUS = paramErr;
  145.                 else {        
  146.                     PACK.lengthOfPathName = lengthOfPathName;
  147.                     STATUS = OCEPackPathName(
  148.                                 parts,
  149.                                 0,
  150.                                 PACK.path,
  151.                                 PACK.lengthOfPathName
  152.                             );
  153.                     LogStatus('DNPn', STATUS, "\pOCEPackPathName");
  154.                 }
  155.             }
  156.             goto ioComplete;
  157.         case kDirGetDNodeAccessControlGet:
  158.             LogText('DCmd', "\pkDirGetDNodeAccessControlGet");
  159.             STATUS = GetRefNumFromRLI(
  160.                         infoPtr,
  161.                         PARAM.getDNodeAccessControlGetPB.pRLI,
  162.                         &refNum
  163.                     );
  164.             goto ioComplete;
  165.         case kDirGetAttributeAccessControlGet:
  166.             LogText('DCmd', "\pkDirAttributeAccessControlGet+");
  167.             /* Fall through */
  168.         case kDirGetRecordAccessControlGet:
  169.             LogText('DCmd', "\pkDirRecordAccessControlGet");
  170.             STATUS = GetRefNumFromRLI(
  171.                         infoPtr,
  172.                         PARAM.getAttributeAccessControlGetPB.aRecord->rli,
  173.                         &refNum
  174.                     );
  175.             /* goto ioComplete; */
  176.             /*
  177.              * The inline calls conclude here.
  178.              */
  179. ioComplete:
  180.             LogStatus('DSts', STATUS, "\pCSAM_DSProc @ ioComplete");
  181.             if (pb->header.ioResult == ioBusy)
  182.                 LogStatus('DSts', pb->header.ioResult, "\pioResult == ioBusy?");
  183.             CallCompletion((ParmBlkPtr) pb);
  184.             break;
  185.         default:
  186.             /*
  187.              * Call the hard stuff. These calls may initiate further I/O.
  188.              * DirParseCommon returns ioBusy (== one) if it was called
  189.              * asychronously and the request is pending. DirParseCommon
  190.              * will call the user ioCompletion routine, if any.
  191.              */
  192.             DirParseCommon(infoPtr, pb, async);
  193.             break;
  194.         }
  195.         LogStatus('DSts', STATUS, "\pCSAM_DSProc @ return");
  196. #ifdef THINK_C
  197.         asm {
  198.             move.l        (sp)+,a4
  199.         }
  200. #endif
  201.         return (STATUS);
  202. #undef PATH
  203. }