Example #1
0
/*
**	GetDesktopFileName
**
**	Get the name of the Desktop file.
*/
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 );
}
Example #2
0
	static OSErr FileGetDates(
		short				iVRefNum,
		long				iDirID,
		ConstStr255Param	iFileName,
		long*				oCrDate,
		long*				oModDate)
		
		{
		HParamBlockRec	pb;
		OSErr			errCode;
		
		pb.fileParam.ioVRefNum		= iVRefNum;
		pb.fileParam.ioFVersNum		= 0;
		pb.fileParam.ioFDirIndex	= 0;
		pb.fileParam.ioNamePtr		= (StringPtr) iFileName;
		pb.fileParam.ioDirID		= iDirID;
		
		errCode = PBHGetFInfoSync(&pb);
		if (errCode != noErr)
			goto punt;
		
		*oCrDate	= pb.fileParam.ioFlCrDat;
		*oModDate	= pb.fileParam.ioFlMdDat;
		
	punt:	
		return errCode;
		}
Example #3
0
pascal	OSErr	FSpSetFInfoCompat(const FSSpec *spec,
                                  const FInfo *fndrInfo)
{
#if !__MACOSSEVENORLATER
    if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() )
    {
        OSErr			result;
        HParamBlockRec	pb;

        pb.fileParam.ioVRefNum = spec->vRefNum;
        pb.fileParam.ioDirID = spec->parID;
        pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
        pb.fileParam.ioFVersNum = 0;
        pb.fileParam.ioFDirIndex = 0;
        result = PBHGetFInfoSync(&pb);
        if ( result == noErr )
        {
            pb.fileParam.ioFlFndrInfo = *fndrInfo;
            pb.fileParam.ioDirID = spec->parID;
            result = PBHSetFInfoSync(&pb);
        }
        return ( result );
    }
    else
#endif	/* !__MACOSSEVENORLATER */
    {
        return ( FSpSetFInfo(spec, fndrInfo) );
    }
}
Example #4
0
int __cdecl _rmdir (
    const char *path
)
{
    ParamBlockRec parm;
    HParamBlockRec hparm;

    OSErr osErr;
    char stPath[256];

    if (!*path || strlen(path) > 255)
    {
        errno = ENOENT;
        return -1;
    }

    strcpy(stPath, path);
    _c2pstr(stPath);

    memset(&hparm, '\0', sizeof(HParamBlockRec));
    hparm.fileParam.ioNamePtr = stPath;

    /* hparm.fileParam.ioVRefNum = 0; */
    /* hparm.fileParam.ioFDirIndex = 0; */

    if ((osErr = PBHGetFInfoSync(&hparm)) == fnfErr)
    {
        memset(&parm, '\0', sizeof(ParamBlockRec));
        parm.fileParam.ioNamePtr = stPath;
        /* parm.fileParam.ioVRefNum = 0; */
        osErr = PBDeleteSync(&parm);
    }
    else if (!osErr)
    {
        osErr = fnfErr;  /* Can't rmdir a file */
    }

    if (osErr)
    {
        /* error occured -- map error code and return */
        _dosmaperr(osErr);
        return -1;
    }
    return 0;

}
Example #5
0
static	OSErr	PreflightFileCopySpace(short srcVRefNum,
									   long srcDirID,
									   ConstStr255Param srcName,
									   ConstStr255Param dstVolName,
									   short dstVRefNum,
									   Boolean *spaceOK)
{
	UniversalFMPB pb;
	OSErr error;
	unsigned long dstFreeBlocks;
	unsigned long dstBlksPerAllocBlk;
	unsigned long srcDataBlks;
	unsigned long srcResourceBlks;
	
	error = XGetVolumeInfoNoName(dstVolName, dstVRefNum, &pb.xPB);
	if ( error == noErr )
	{
		/* get allocation block size (always multiple of 512) and divide by 512
		  to get number of 512-byte blocks per allocation block */
		dstBlksPerAllocBlk = ((unsigned long)pb.xPB.ioVAlBlkSiz >> 9);
		
		/* Convert freeBytes to free disk blocks (512-byte blocks) */
		dstFreeBlocks = U32SetU(U64ShiftRight(pb.xPB.ioVFreeBytes, 9));
		
		/* Now, get the size of the file's data resource forks */
		pb.hPB.fileParam.ioNamePtr = (StringPtr)srcName;
		pb.hPB.fileParam.ioVRefNum = srcVRefNum;
		pb.hPB.fileParam.ioFVersNum = 0;
		pb.hPB.fileParam.ioDirID = srcDirID;
		pb.hPB.fileParam.ioFDirIndex = 0;
		error = PBHGetFInfoSync(&pb.hPB);
		if ( error == noErr )
		{
			/* Since space on Mac OS disks is always allocated in allocation blocks, */
			/* this code takes into account rounding up to the end of an allocation block. */

			/* get number of 512-byte blocks needed for data fork */
			if ( ((unsigned long)pb.hPB.fileParam.ioFlLgLen & 0x000001ff) != 0 )
			{
				srcDataBlks = ((unsigned long)pb.hPB.fileParam.ioFlLgLen >> 9) + 1;
			}
			else
			{
Example #6
0
static	OSErr	CheckForForks(short vRefNum,
							  long dirID,
							  ConstStr255Param name,
							  Boolean *hasDataFork,
							  Boolean *hasResourceFork)
{
	HParamBlockRec pb;
	OSErr error;
	
	pb.fileParam.ioNamePtr = (StringPtr)name;
	pb.fileParam.ioVRefNum = vRefNum;
	pb.fileParam.ioFVersNum = 0;
	pb.fileParam.ioDirID = dirID;
	pb.fileParam.ioFDirIndex = 0;
	error = PBHGetFInfoSync(&pb);
	*hasDataFork = (pb.fileParam.ioFlLgLen != 0);
	*hasResourceFork = (pb.fileParam.ioFlRLgLen != 0);
	
	return ( error );
}
Example #7
0
pascal	OSErr	DTXGetAPPL(ConstStr255Param volName,
						   short vRefNum,
						   OSType creator,
						   Boolean searchCatalog,
						   short *applVRefNum,
						   long *applParID,
						   Str255 applName)
{
	OSErr error;
	UniversalFMPB pb;
	short dtRefNum;
	Boolean newDTDatabase;
	short realVRefNum;
	short index;
	Boolean applFound;
	FSSpec spec;
	long actMatchCount;
	
	/* get the real vRefNum */
	error = DetermineVRefNum(volName, vRefNum, &realVRefNum);
	if ( error == noErr )
	{
		error = DTOpen(volName, vRefNum, &dtRefNum, &newDTDatabase);
		if ( error == noErr )
		{
			if ( !newDTDatabase )
			{
				index = 0;
				applFound = false;
				do
				{
					pb.dtPB.ioNamePtr = applName;
					pb.dtPB.ioDTRefNum = dtRefNum;
					pb.dtPB.ioIndex = index;
					pb.dtPB.ioFileCreator = creator;
					error = PBDTGetAPPLSync(&pb.dtPB);
					if ( error == noErr )
					{
						/* got a match - see if it is valid */
						
						*applVRefNum = realVRefNum; /* get the vRefNum now */
						*applParID = pb.dtPB.ioAPPLParID; /* get the parent ID now */
	
						/* pb.hPB.fileParam.ioNamePtr is already set */
						pb.hPB.fileParam.ioVRefNum = realVRefNum;
						pb.hPB.fileParam.ioFVersNum = 0;
						pb.hPB.fileParam.ioDirID = *applParID;
						pb.hPB.fileParam.ioFDirIndex = 0;	/* use ioNamePtr and ioDirID */
						if ( PBHGetFInfoSync(&pb.hPB) == noErr )
						{
							if ( (pb.hPB.fileParam.ioFlFndrInfo.fdCreator == creator) &&
								 (pb.hPB.fileParam.ioFlFndrInfo.fdType == 'APPL') )
							{
								applFound = true;
							}
						}
					}
					++index;
				} while ( (error == noErr) && !applFound );
				if ( error != noErr )
				{
					error = afpItemNotFound;
				}
			}
			else
			{
				/* Desktop database is empty (new), set error to try CatSearch */
				error = afpItemNotFound;
			}
		}
		/* acceptable errors from Desktop Manager to continue are paramErr or afpItemNotFound */
		if ( error == paramErr )
		{
			/* if paramErr, the volume didn't support the Desktop Manager */
			/* try the Desktop file */
			
			error = GetAPPLFromDesktopFile(volName, vRefNum, creator,
											applVRefNum, applParID, applName);
			if ( error == noErr )
			{
				/* got a match - see if it is valid */
				
				pb.hPB.fileParam.ioNamePtr = applName;
				pb.hPB.fileParam.ioVRefNum = *applVRefNum;
				pb.hPB.fileParam.ioFVersNum = 0;
				pb.hPB.fileParam.ioDirID = *applParID;
				pb.hPB.fileParam.ioFDirIndex = 0;	/* use ioNamePtr and ioDirID */
				if ( PBHGetFInfoSync(&pb.hPB) == noErr )
				{
					if ( (pb.hPB.fileParam.ioFlFndrInfo.fdCreator != creator) ||
						 (pb.hPB.fileParam.ioFlFndrInfo.fdType != 'APPL') )
					{
						error = afpItemNotFound;
					}
				}
				else if ( error == fnfErr )
				{
					error = afpItemNotFound;
				}
			}
		}
		/* acceptable error from DesktopFile code to continue is afpItemNotFound */
		if ( (error == afpItemNotFound) && searchCatalog)
		{
			/* Couldn't be found in the Desktop file either, */
			/* try searching with CatSearch if requested */
			
			error = CreatorTypeFileSearch(NULL, realVRefNum, creator, kAPPLResType, &spec, 1,
											&actMatchCount, true);
			if ( (error == noErr) || (error == eofErr) )
			{
				if ( actMatchCount > 0 )
				{
					*applVRefNum = spec.vRefNum;
					*applParID = spec.parID;
					BlockMoveData(spec.name, applName, spec.name[0] + 1);
				}
				else
				{
					error = afpItemNotFound;
				}
			}
		}
	}
	
	return ( error );
}