12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724 |
- #include <string.h>
- #include "macstuff.h"
- extern int errno;
- static OSErr GetCommentFromDesktopFile(short vRefNum,
- long dirID,
- ConstStr255Param name,
- Str255 comment);
- static OSErr GetCommentID(short vRefNum,
- long dirID,
- ConstStr255Param name,
- short *commentID);
- static OSErr GetDesktopFileName(short vRefNum,
- Str255 desktopName);
- enum
- {
- kBNDLResType = 'BNDL',
- kFREFResType = 'FREF',
- kIconFamResType = 'ICN#',
- kFCMTResType = 'FCMT',
- kAPPLResType = 'APPL'
- };
- pascal OSErr FSMakeFSSpecCompat(short vRefNum,
- long dirID,
- ConstStr255Param fileName,
- FSSpec *spec)
- {
- OSErr result;
- #if !__MACOSSEVENORLATER
- if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() )
- {
- Boolean isDirectory;
- result = GetObjectLocation(vRefNum, dirID, fileName,
- &(spec->vRefNum), &(spec->parID), spec->name,
- &isDirectory);
- }
- else
- #endif
- {
-
-
- result = FSMakeFSSpec(vRefNum, dirID, fileName, spec);
-
-
-
-
- if ( (result == noErr) && (spec->parID == 0) )
- spec->parID = fsRtParID;
- }
- return ( result );
- }
- #if !__MACOSSEVENORLATER
- static Boolean FSHasFSSpecCalls(void)
- {
- long response;
- #if !GENERATENODATA
- static Boolean tested = false;
- static Boolean result = false;
- #else
- Boolean result = false;
- #endif
- #if !GENERATENODATA
- if ( !tested )
- {
- tested = true;
- #endif
- if ( Gestalt(gestaltFSAttr, &response) == noErr )
- {
- result = ((response & (1L << gestaltHasFSSpecCalls)) != 0);
- }
- #if !GENERATENODATA
- }
- #endif
- return ( result );
- }
- #endif
- #if !__MACOSSEVENORLATER
- static Boolean QTHasFSSpecCalls(void)
- {
- long response;
- #if !GENERATENODATA
- static Boolean tested = false;
- static Boolean result = false;
- #else
- Boolean result = false;
- #endif
- #if !GENERATENODATA
- if ( !tested )
- {
- tested = true;
- #endif
- result = (Gestalt(gestaltQuickTimeVersion, &response) == noErr);
- #if !GENERATENODATA
- }
- #endif
- return ( result );
- }
- #endif
- int FSpGetDefaultDir(FSSpecPtr dirSpec)
- {
- OSErr err;
- short vRefNum = 0;
- long int dirID = 0;
- err = HGetVol(NULL, &vRefNum, &dirID);
- if (err == noErr) {
- err = FSMakeFSSpecCompat(vRefNum, dirID, (ConstStr255Param) NULL,
- dirSpec);
- }
- return err;
- }
- int FSpSetDefaultDir(FSSpecPtr dirSpec)
- {
- OSErr err;
-
- if (dirSpec->parID == fsRtParID) {
- err = HSetVol(NULL, dirSpec->vRefNum, fsRtDirID);
- } else {
- err = HSetVol(dirSpec->name, dirSpec->vRefNum, dirSpec->parID);
- }
- return err;
- }
- OSErr
- FSpFindFolder(
- short vRefNum,
- OSType folderType,
- Boolean createFolder,
- FSSpec *spec)
- {
- short foundVRefNum;
- long foundDirID;
- OSErr err;
- err = FindFolder(vRefNum, folderType, createFolder,
- &foundVRefNum, &foundDirID);
- if (err != noErr) {
- return err;
- }
- err = FSMakeFSSpecCompat(foundVRefNum, foundDirID, "\p", spec);
- return err;
- }
- OSErr
- FSpPathFromLocation(
- FSSpec *spec,
- int *length,
- Handle *fullPath)
- {
- OSErr err;
- FSSpec tempSpec;
- CInfoPBRec pb;
- *fullPath = NULL;
-
- BlockMoveData(spec, &tempSpec, sizeof(FSSpec));
- if (tempSpec.parID == fsRtParID) {
-
- tempSpec.name[0] += 2;
- tempSpec.name[tempSpec.name[0] - 1] = ':';
- tempSpec.name[tempSpec.name[0]] = '\0';
- err = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]);
- } else {
-
- pb.dirInfo.ioNamePtr = tempSpec.name;
- pb.dirInfo.ioVRefNum = tempSpec.vRefNum;
- pb.dirInfo.ioDrDirID = tempSpec.parID;
- pb.dirInfo.ioFDirIndex = 0;
- err = PBGetCatInfoSync(&pb);
- if ((err == noErr) || (err == fnfErr)) {
-
- if (err == fnfErr) {
- BlockMoveData(spec, &tempSpec, sizeof(FSSpec));
- } else if ( (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) {
- tempSpec.name[0] += 1;
- tempSpec.name[tempSpec.name[0]] = ':';
- }
-
- tempSpec.name[0] += 1;
- tempSpec.name[tempSpec.name[0]] = '\0';
- err = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]);
- if (err == noErr) {
-
- pb.dirInfo.ioNamePtr = tempSpec.name;
- pb.dirInfo.ioVRefNum = tempSpec.vRefNum;
- pb.dirInfo.ioDrParID = tempSpec.parID;
- do {
- pb.dirInfo.ioFDirIndex = -1;
- pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
- err = PBGetCatInfoSync(&pb);
- if (err == noErr) {
-
- ++tempSpec.name[0];
- tempSpec.name[tempSpec.name[0]] = ':';
- (void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1],
- tempSpec.name[0]);
- err = MemError();
- }
- } while ( (err == noErr) &&
- (pb.dirInfo.ioDrDirID != fsRtDirID) );
- }
- }
- }
-
- if (err == noErr) {
- *length = GetHandleSize(*fullPath) - 1;
- } else {
- if ( *fullPath != NULL ) {
- DisposeHandle(*fullPath);
- }
- *fullPath = NULL;
- *length = 0;
- }
- return err;
- }
- pascal OSErr FSpGetDirectoryID(const FSSpec *spec,
- long *theDirID,
- Boolean *isDirectory)
- {
- return ( GetDirectoryID(spec->vRefNum, spec->parID, spec->name,
- theDirID, isDirectory) );
- }
- pascal OSErr GetDirectoryID(short vRefNum,
- long dirID,
- ConstStr255Param name,
- long *theDirID,
- Boolean *isDirectory)
- {
- CInfoPBRec pb;
- OSErr error;
- error = GetCatInfoNoName(vRefNum, dirID, name, &pb);
- if ( error == noErr )
- {
- *isDirectory = (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0;
- if ( *isDirectory )
- {
- *theDirID = pb.dirInfo.ioDrDirID;
- }
- else
- {
- *theDirID = pb.hFileInfo.ioFlParID;
- }
- }
- return ( error );
- }
- pascal OSErr GetCatInfoNoName(short vRefNum,
- long dirID,
- ConstStr255Param name,
- CInfoPBPtr pb)
- {
- Str31 tempName;
- OSErr error;
-
- if ( (name == NULL) || (name[0] == 0) )
- {
- tempName[0] = 0;
- pb->dirInfo.ioNamePtr = tempName;
- pb->dirInfo.ioFDirIndex = -1;
- }
- else
- {
- pb->dirInfo.ioNamePtr = (StringPtr)name;
- pb->dirInfo.ioFDirIndex = 0;
- }
- pb->dirInfo.ioVRefNum = vRefNum;
- pb->dirInfo.ioDrDirID = dirID;
- error = PBGetCatInfoSync(pb);
- pb->dirInfo.ioNamePtr = NULL;
- return ( error );
- }
- pascal OSErr GetObjectLocation(short vRefNum,
- long dirID,
- ConstStr255Param pathname,
- short *realVRefNum,
- long *realParID,
- Str255 realName,
- Boolean *isDirectory)
- {
- OSErr error;
- CInfoPBRec pb;
- Str255 tempPathname;
-
- *realVRefNum = 0;
- *realParID = 0;
- realName[0] = 0;
-
- error = DetermineVRefNum(pathname, vRefNum, realVRefNum);
- if ( error == noErr )
- {
-
-
- if ( (pathname == NULL) || (pathname[0] == 0) )
- {
- tempPathname[0] = 0;
- pb.hFileInfo.ioNamePtr = tempPathname;
- pb.hFileInfo.ioFDirIndex = -1;
- }
- else
- {
- pb.hFileInfo.ioNamePtr = (StringPtr)pathname;
- pb.hFileInfo.ioFDirIndex = 0;
- }
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- error = PBGetCatInfoSync(&pb);
- if ( error == noErr )
- {
-
-
- *isDirectory = (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0;
- if ( *isDirectory )
- {
-
- pb.dirInfo.ioNamePtr = realName;
- pb.dirInfo.ioVRefNum = *realVRefNum;
-
- pb.dirInfo.ioFDirIndex = -1;
- error = PBGetCatInfoSync(&pb);
-
-
- *realParID = pb.dirInfo.ioDrParID;
- }
- else
- {
-
- *realParID = pb.hFileInfo.ioFlParID;
- error = GetFilenameFromPathname(pathname, realName);
- }
- }
- else if ( error == fnfErr )
- {
-
-
- error = GetFilenameFromPathname(pathname, realName);
-
- if ( error == noErr )
- {
-
-
- BlockMoveData(pathname, tempPathname, pathname[0] + 1);
-
- tempPathname[0] -= realName[0];
-
- if ( pathname[pathname[0]] == ':' )
- {
- --tempPathname[0];
- }
-
-
- pb.hFileInfo.ioNamePtr = (StringPtr)tempPathname;
- if ( tempPathname[0] != 0 )
- {
- pb.hFileInfo.ioFDirIndex = 0;
- }
- else
- {
- pb.hFileInfo.ioFDirIndex = -1;
- }
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- error = PBGetCatInfoSync(&pb);
- *realParID = pb.dirInfo.ioDrDirID;
- *isDirectory = false;
- }
- if ( error != noErr )
- {
- error = dirNFErr;
- }
- else
- {
- error = fnfErr;
- }
- }
- }
- return ( error );
- }
- pascal OSErr DetermineVRefNum(ConstStr255Param pathname,
- short vRefNum,
- short *realVRefNum)
- {
- HParamBlockRec pb;
- OSErr error;
- error = GetVolumeInfoNoName(pathname,vRefNum, &pb);
- if ( error == noErr )
- {
- *realVRefNum = pb.volumeParam.ioVRefNum;
- }
- return ( error );
- }
- pascal OSErr GetFilenameFromPathname(ConstStr255Param pathname,
- Str255 filename)
- {
- short index;
- short nameEnd;
- OSErr error;
-
- filename[0] = 0;
-
- if ( pathname != NULL )
- {
-
- index = pathname[0];
-
- if ( index != 0 )
- {
-
- if ( pathname[index] == ':' )
- {
- --index;
- }
-
- nameEnd = index;
-
-
- if ( pathname[index] != ':' )
- {
-
- while ( (index != 0) && (pathname[index] != ':') )
- {
- --index;
- }
-
-
- if ( (index != 0) || (pathname[pathname[0]] != ':') )
- {
-
- filename[0] = (char)(nameEnd - index);
- BlockMoveData(&pathname[index+1], &filename[1], nameEnd - index);
- error = noErr;
- }
- else
- {
-
- error = notAFileErr;
- }
- }
- else
- {
-
- error = notAFileErr;
- }
- }
- else
- {
-
- error = notAFileErr;
- }
- }
- else
- {
-
- error = notAFileErr;
- }
- return ( error );
- }
- pascal OSErr GetVolumeInfoNoName(ConstStr255Param pathname,
- short vRefNum,
- HParmBlkPtr pb)
- {
- Str255 tempPathname;
- OSErr error;
-
- if ( pb != NULL )
- {
- pb->volumeParam.ioVRefNum = vRefNum;
- if ( pathname == NULL )
- {
- pb->volumeParam.ioNamePtr = NULL;
- pb->volumeParam.ioVolIndex = 0;
- }
- else
- {
- BlockMoveData(pathname, tempPathname, pathname[0] + 1);
-
- pb->volumeParam.ioNamePtr = (StringPtr)tempPathname;
-
- pb->volumeParam.ioVolIndex = -1;
- }
- error = PBHGetVInfoSync(pb);
- pb->volumeParam.ioNamePtr = NULL;
- }
- else
- {
- error = paramErr;
- }
- return ( error );
- }
- pascal OSErr FSpGetFullPath(const FSSpec *spec,
- short *fullPathLength,
- Handle *fullPath)
- {
- OSErr result;
- OSErr realResult;
- FSSpec tempSpec;
- CInfoPBRec pb;
- *fullPathLength = 0;
- *fullPath = NULL;
-
- realResult = noErr;
-
- BlockMoveData(spec, &tempSpec, sizeof(FSSpec));
- if ( tempSpec.parID == fsRtParID )
- {
-
-
- ++tempSpec.name[0];
- tempSpec.name[tempSpec.name[0]] = ':';
-
- result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]);
- }
- else
- {
-
-
- pb.dirInfo.ioNamePtr = tempSpec.name;
- pb.dirInfo.ioVRefNum = tempSpec.vRefNum;
- pb.dirInfo.ioDrDirID = tempSpec.parID;
- pb.dirInfo.ioFDirIndex = 0;
- result = PBGetCatInfoSync(&pb);
-
- realResult = result;
- if ( (result == noErr) || (result == fnfErr) )
- {
-
- if ( (result == noErr) && (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0 )
- {
- ++tempSpec.name[0];
- tempSpec.name[tempSpec.name[0]] = ':';
- }
-
- result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]);
- if ( result == noErr )
- {
-
- pb.dirInfo.ioNamePtr = tempSpec.name;
- pb.dirInfo.ioVRefNum = tempSpec.vRefNum;
- pb.dirInfo.ioDrParID = tempSpec.parID;
- do
- {
- pb.dirInfo.ioFDirIndex = -1;
- pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
- result = PBGetCatInfoSync(&pb);
- if ( result == noErr )
- {
-
- ++tempSpec.name[0];
- tempSpec.name[tempSpec.name[0]] = ':';
-
- (void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1],
- tempSpec.name[0]);
- result = MemError();
- }
- } while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) );
- }
- }
- }
- if ( result == noErr )
- {
-
- *fullPathLength = InlineGetHandleSize(*fullPath);
- result = realResult;
- }
- else
- {
-
- if ( *fullPath != NULL )
- {
- DisposeHandle(*fullPath);
- }
- *fullPath = NULL;
- *fullPathLength = 0;
- }
- return ( result );
- }
- pascal OSErr FSpLocationFromFullPath(short fullPathLength,
- const void *fullPath,
- FSSpec *spec)
- {
- AliasHandle alias;
- OSErr result;
- Boolean wasChanged;
- Str32 nullString;
-
- nullString[0] = 0;
- result = NewAliasMinimalFromFullPath(fullPathLength, fullPath, nullString,
- nullString, &alias);
- if ( result == noErr )
- {
-
- result = ResolveAlias(NULL, alias, spec, &wasChanged);
- DisposeHandle((Handle)alias);
- }
- return ( result );
- }
- pascal OSErr GetFullPath(short vRefNum,
- long dirID,
- ConstStr255Param name,
- short *fullPathLength,
- Handle *fullPath)
- {
- OSErr result;
- FSSpec spec;
- *fullPathLength = 0;
- *fullPath = NULL;
- result = FSMakeFSSpecCompat(vRefNum, dirID, name, &spec);
- if ( (result == noErr) || (result == fnfErr) )
- {
- result = FSpGetFullPath(&spec, fullPathLength, fullPath);
- }
- return ( result );
- }
- pascal OSErr ChangeCreatorType(short vRefNum,
- long dirID,
- ConstStr255Param name,
- OSType creator,
- OSType fileType)
- {
- CInfoPBRec pb;
- OSErr error;
- short realVRefNum;
- long parID;
- pb.hFileInfo.ioNamePtr = (StringPtr)name;
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- pb.hFileInfo.ioFDirIndex = 0;
- error = PBGetCatInfoSync(&pb);
- if ( error == noErr )
- {
- if ( (pb.hFileInfo.ioFlAttrib & ioDirMask) == 0 )
- {
- parID = pb.hFileInfo.ioFlParID;
-
- if ( creator != (OSType)0x00000000 )
- {
- pb.hFileInfo.ioFlFndrInfo.fdCreator = creator;
- }
-
- if ( fileType != (OSType)0x00000000 )
- {
- pb.hFileInfo.ioFlFndrInfo.fdType = fileType;
- }
- pb.hFileInfo.ioDirID = dirID;
- error = PBSetCatInfoSync(&pb);
- if ( (error == noErr) && (parID != fsRtParID) )
- {
-
- error = DetermineVRefNum(name, vRefNum, &realVRefNum);
- if ( error == noErr )
- {
- error = BumpDate(realVRefNum, parID, NULL);
-
-
- }
- }
- }
- else
- {
-
- error = notAFileErr;
- }
- }
- return ( error );
- }
- pascal OSErr FSpChangeCreatorType(const FSSpec *spec,
- OSType creator,
- OSType fileType)
- {
- return ( ChangeCreatorType(spec->vRefNum, spec->parID, spec->name,
- creator, fileType) );
- }
- pascal OSErr BumpDate(short vRefNum,
- long dirID,
- ConstStr255Param name)
- {
- CInfoPBRec pb;
- Str31 tempName;
- OSErr error;
- unsigned long secs;
-
- if ( (name == NULL) || (name[0] == 0) )
- {
- tempName[0] = 0;
- pb.hFileInfo.ioNamePtr = tempName;
- pb.hFileInfo.ioFDirIndex = -1;
- }
- else
- {
- pb.hFileInfo.ioNamePtr = (StringPtr)name;
- pb.hFileInfo.ioFDirIndex = 0;
- }
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- error = PBGetCatInfoSync(&pb);
- if ( error == noErr )
- {
- GetDateTime(&secs);
-
- pb.hFileInfo.ioFlMdDat =
- (secs == pb.hFileInfo.ioFlMdDat) ? (++secs) : (secs);
- if ( pb.dirInfo.ioNamePtr == tempName )
- {
- pb.hFileInfo.ioDirID = pb.hFileInfo.ioFlParID;
- }
- else
- {
- pb.hFileInfo.ioDirID = dirID;
- }
- error = PBSetCatInfoSync(&pb);
- }
- return ( error );
- }
- pascal OSErr FSpBumpDate(const FSSpec *spec)
- {
- return ( BumpDate(spec->vRefNum, spec->parID, spec->name) );
- }
- pascal OSErr OnLine(FSSpecPtr volumes,
- short reqVolCount,
- short *actVolCount,
- short *volIndex)
- {
- HParamBlockRec pb;
- OSErr error = noErr;
- FSSpec *endVolArray;
- if ( *volIndex > 0 )
- {
- *actVolCount = 0;
- for ( endVolArray = volumes + reqVolCount;
- (volumes < endVolArray) && (error == noErr); ++volumes )
- {
- pb.volumeParam.ioNamePtr = (StringPtr) & volumes->name;
- pb.volumeParam.ioVolIndex = *volIndex;
- error = PBHGetVInfoSync(&pb);
- if ( error == noErr )
- {
- volumes->parID = fsRtParID;
- volumes->vRefNum = pb.volumeParam.ioVRefNum;
- ++*volIndex;
- ++*actVolCount;
- }
- }
- }
- else
- {
- error = paramErr;
- }
- return ( error );
- }
- pascal OSErr DTGetComment(short vRefNum,
- long dirID,
- ConstStr255Param name,
- Str255 comment)
- {
- DTPBRec pb;
- OSErr error;
- short dtRefNum;
- Boolean newDTDatabase;
- if (comment != NULL)
- {
- comment[0] = 0;
-
- error = DTOpen(name, vRefNum, &dtRefNum, &newDTDatabase);
- if ( error == noErr )
- {
-
- if ( !newDTDatabase )
- {
- pb.ioDTRefNum = dtRefNum;
- pb.ioNamePtr = (StringPtr)name;
- pb.ioDirID = dirID;
- pb.ioDTBuffer = (Ptr)&comment[1];
-
- pb.ioDTReqCount = sizeof(Str255) - 1;
- error = PBDTGetCommentSync(&pb);
- if (error == noErr)
- {
- comment[0] = (unsigned char)pb.ioDTActCount;
- }
- }
- }
- else
- {
-
- error = GetCommentFromDesktopFile(vRefNum, dirID, name, comment);
- if ( error != noErr )
- {
- error = afpItemNotFound;
- }
- }
- }
- else
- {
- error = paramErr;
- }
- return (error);
- }
- pascal OSErr FSpDTGetComment(const FSSpec *spec,
- Str255 comment)
- {
- return (DTGetComment(spec->vRefNum, spec->parID, spec->name, comment));
- }
- pascal OSErr DTSetComment(short vRefNum,
- long dirID,
- ConstStr255Param name,
- ConstStr255Param comment)
- {
- DTPBRec pb;
- OSErr error;
- short dtRefNum;
- Boolean newDTDatabase;
- error = DTOpen(name, vRefNum, &dtRefNum, &newDTDatabase);
- if ( error == noErr )
- {
- pb.ioDTRefNum = dtRefNum;
- pb.ioNamePtr = (StringPtr)name;
- pb.ioDirID = dirID;
- pb.ioDTBuffer = (Ptr)&comment[1];
-
-
- if ( comment[0] <= 200 )
- {
- pb.ioDTReqCount = comment[0];
- }
- else
- {
- pb.ioDTReqCount = 200;
- }
- error = PBDTSetCommentSync(&pb);
- }
- return (error);
- }
- pascal OSErr FSpDTSetComment(const FSSpec *spec,
- ConstStr255Param comment)
- {
- return (DTSetComment(spec->vRefNum, spec->parID, spec->name, comment));
- }
- pascal OSErr DTOpen(ConstStr255Param volName,
- short vRefNum,
- short *dtRefNum,
- Boolean *newDTDatabase)
- {
- OSErr error;
- GetVolParmsInfoBuffer volParmsInfo;
- long infoSize;
- DTPBRec pb;
-
- infoSize = sizeof(GetVolParmsInfoBuffer);
- error = HGetVolParms(volName, vRefNum, &volParmsInfo, &infoSize);
- if ( error == noErr )
- {
- if ( hasDesktopMgr(volParmsInfo) )
- {
- pb.ioNamePtr = (StringPtr)volName;
- pb.ioVRefNum = vRefNum;
- error = PBDTOpenInform(&pb);
-
-
- *newDTDatabase = ((pb.ioTagInfo & 1L) == 0);
- if ( error == paramErr )
- {
- error = PBDTGetPath(&pb);
-
-
- *newDTDatabase = false;
- }
- *dtRefNum = pb.ioDTRefNum;
- }
- else
- {
- error = paramErr;
- }
- }
- return ( error );
- }
- static OSErr GetCommentFromDesktopFile(short vRefNum,
- long dirID,
- ConstStr255Param name,
- Str255 comment)
- {
- OSErr error;
- short commentID;
- short realVRefNum;
- Str255 desktopName;
- short savedResFile;
- short dfRefNum;
- StringHandle commentHandle;
-
- error = GetCommentID(vRefNum, dirID, name, &commentID);
- if ( error == noErr )
- {
- if ( commentID != 0 )
- {
- error = DetermineVRefNum(name, vRefNum, &realVRefNum);
- if ( error == noErr )
- {
- error = GetDesktopFileName(realVRefNum, desktopName);
- if ( error == noErr )
- {
- savedResFile = CurResFile();
-
- SetResLoad(false);
- dfRefNum = HOpenResFile(realVRefNum, fsRtDirID, desktopName,
- fsRdPerm);
- SetResLoad(true);
- if ( dfRefNum != -1)
- {
-
- commentHandle = (StringHandle)Get1Resource(kFCMTResType,
- commentID);
- if ( commentHandle != NULL )
- {
- if ( InlineGetHandleSize((Handle)commentHandle) > 0 )
- {
- BlockMoveData(*commentHandle, comment,
- *commentHandle[0] + 1);
- }
- else
- {
- error = afpItemNotFound;
- }
- }
- else
- {
- error = afpItemNotFound;
- }
-
- UseResFile(savedResFile);
- CloseResFile(dfRefNum);
- }
- else
- {
- error = afpItemNotFound;
- }
- }
- else
- {
- error = afpItemNotFound;
- }
- }
- }
- else
- {
- error = afpItemNotFound;
- }
- }
- return ( error );
- }
- pascal OSErr HGetVolParms(ConstStr255Param volName,
- short vRefNum,
- GetVolParmsInfoBuffer *volParmsInfo,
- long *infoSize)
- {
- HParamBlockRec pb;
- OSErr error;
- pb.ioParam.ioNamePtr = (StringPtr)volName;
- pb.ioParam.ioVRefNum = vRefNum;
- pb.ioParam.ioBuffer = (Ptr)volParmsInfo;
- pb.ioParam.ioReqCount = *infoSize;
- error = PBHGetVolParmsSync(&pb);
- if ( error == noErr )
- {
- *infoSize = pb.ioParam.ioActCount;
- }
- return ( error );
- }
- static OSErr GetCommentID(short vRefNum,
- long dirID,
- ConstStr255Param name,
- short *commentID)
- {
- CInfoPBRec pb;
- OSErr error;
- error = GetCatInfoNoName(vRefNum, dirID, name, &pb);
- *commentID = pb.hFileInfo.ioFlXFndrInfo.fdComment;
- return ( error );
- }
- static OSErr GetDesktopFileName(short vRefNum,
- Str255 desktopName)
- {
- OSErr error;
- HParamBlockRec pb;
- short index;
- Boolean found;
- pb.fileParam.ioNamePtr = desktopName;
- pb.fileParam.ioVRefNum = vRefNum;
- pb.fileParam.ioFVersNum = 0;
- index = 1;
- found = false;
- do
- {
- pb.fileParam.ioDirID = fsRtDirID;
- pb.fileParam.ioFDirIndex = index;
- error = PBHGetFInfoSync(&pb);
- if ( error == noErr )
- {
- if ( (pb.fileParam.ioFlFndrInfo.fdType == 'FNDR') &&
- (pb.fileParam.ioFlFndrInfo.fdCreator == 'ERIK') )
- {
- found = true;
- }
- }
- ++index;
- } while ( (error == noErr) && !found );
- return ( error );
- }
- pascal OSErr XGetVInfo(short volReference,
- StringPtr volName,
- short *vRefNum,
- UnsignedWide *freeBytes,
- UnsignedWide *totalBytes)
- {
- OSErr result;
- long response;
- XVolumeParam pb;
-
- if ( ( Gestalt(gestaltFSAttr, &response) == noErr ) && ((response & (1L << gestaltFSSupports2TBVols)) != 0) )
- {
-
- pb.ioVRefNum = volReference;
- pb.ioNamePtr = volName;
- pb.ioXVersion = 0;
- pb.ioVolIndex = 0;
- result = PBXGetVolInfoSync(&pb);
- if ( result == noErr )
- {
-
-
- *vRefNum = pb.ioVRefNum;
-
- *totalBytes = pb.ioVTotalBytes;
- *freeBytes = pb.ioVFreeBytes;
- }
- }
- else
- {
-
-
- result = HGetVInfo(volReference, volName, vRefNum, &freeBytes->lo, &totalBytes->lo);
- if ( result == noErr )
- {
-
- totalBytes->hi = 0;
- freeBytes->hi = 0;
- }
- }
- return ( result );
- }
- pascal OSErr HGetVInfo(short volReference,
- StringPtr volName,
- short *vRefNum,
- unsigned long *freeBytes,
- unsigned long *totalBytes)
- {
- HParamBlockRec pb;
- unsigned long allocationBlockSize;
- unsigned short numAllocationBlocks;
- unsigned short numFreeBlocks;
- VCB *theVCB;
- Boolean vcbFound;
- OSErr result;
-
- pb.volumeParam.ioVRefNum = volReference;
- pb.volumeParam.ioNamePtr = volName;
- pb.volumeParam.ioVolIndex = 0;
- result = PBHGetVInfoSync(&pb);
- if ( result == noErr )
- {
-
-
- *vRefNum = pb.volumeParam.ioVRefNum;
- allocationBlockSize = (unsigned long)pb.volumeParam.ioVAlBlkSiz;
-
-
-
-
-
-
-
-
-
- vcbFound = false;
- theVCB = (VCB *)(GetVCBQHdr()->qHead);
- while ( (theVCB != NULL) && !vcbFound )
- {
-
-
- if ( theVCB->vcbSigWord == 0x4244 )
- {
- if ( theVCB->vcbVRefNum == *vRefNum )
- {
- vcbFound = true;
- }
- }
- if ( !vcbFound )
- {
- theVCB = (VCB *)(theVCB->qLink);
- }
- }
- if ( theVCB != NULL )
- {
-
-
- numAllocationBlocks = (unsigned short)theVCB->vcbNmAlBlks;
- numFreeBlocks = (unsigned short)theVCB->vcbFreeBks;
- }
- else
- {
-
-
- numAllocationBlocks = (unsigned short)pb.volumeParam.ioVNmAlBlks;
- numFreeBlocks = (unsigned short)pb.volumeParam.ioVFrBlk;
- }
-
- *freeBytes = numFreeBlocks * allocationBlockSize;
- *totalBytes = numAllocationBlocks * allocationBlockSize;
- }
- return ( result );
- }
- #if __WANTPASCALELIMINATION
- #undef pascal
- #endif
- #if GENERATINGCFM
- pascal OSErr PBXGetVolInfoSync(XVolumeParamPtr paramBlock)
- {
- enum
- {
- kXGetVolInfoSelector = 0x0012,
- uppFSDispatchProcInfo = kRegisterBased
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(long)))
- | REGISTER_ROUTINE_PARAMETER(2, kRegisterD0, SIZE_CODE(sizeof(long)))
- | REGISTER_ROUTINE_PARAMETER(3, kRegisterA0, SIZE_CODE(sizeof(XVolumeParamPtr)))
- };
- return ( CallOSTrapUniversalProc(NGetTrapAddress(_FSDispatch, OSTrap),
- uppFSDispatchProcInfo,
- _FSDispatch,
- kXGetVolInfoSelector,
- paramBlock) );
- }
- #endif
- #if __WANTPASCALELIMINATION
- #define pascal
- #endif
- pascal OSErr GetDirName(short vRefNum,
- long dirID,
- Str31 name)
- {
- CInfoPBRec pb;
- OSErr error;
- if ( name != NULL )
- {
- pb.dirInfo.ioNamePtr = name;
- pb.dirInfo.ioVRefNum = vRefNum;
- pb.dirInfo.ioDrDirID = dirID;
- pb.dirInfo.ioFDirIndex = -1;
- error = PBGetCatInfoSync(&pb);
- }
- else
- {
- error = paramErr;
- }
- return ( error );
- }
- pascal OSErr GetVolFileSystemID(ConstStr255Param pathname,
- short vRefNum,
- short *fileSystemID)
- {
- HParamBlockRec pb;
- OSErr error;
- error = GetVolumeInfoNoName(pathname,vRefNum, &pb);
- if ( error == noErr )
- {
- *fileSystemID = pb.volumeParam.ioVFSID;
- }
- return ( error );
- }
- pascal OSErr GetDInfo(short vRefNum,
- long dirID,
- ConstStr255Param name,
- DInfo *fndrInfo)
- {
- CInfoPBRec pb;
- OSErr error;
- error = GetCatInfoNoName(vRefNum, dirID, name, &pb);
- if ( error == noErr )
- {
- if ( (pb.dirInfo.ioFlAttrib & ioDirMask) != 0 )
- {
-
- *fndrInfo = pb.dirInfo.ioDrUsrWds;
- }
- else
- {
-
- error = dirNFErr;
- }
- }
- return ( error );
- }
- pascal OSErr FSpGetDInfo(const FSSpec *spec,
- DInfo *fndrInfo)
- {
- return ( GetDInfo(spec->vRefNum, spec->parID, spec->name, fndrInfo) );
- }
|