Exemple #1
0
/*
**	GetVolumeInfoNoName uses pathname and vRefNum to call PBHGetVInfoSync
**	in cases where the returned volume name is not needed by the caller.
**	The pathname and vRefNum parameters are not touched, and the pb
**	parameter is initialized by PBHGetVInfoSync except that ioNamePtr in
**	the parameter block is always returned as NULL (since it might point
**	to the local tempPathname).
**
**	I noticed using this code in several places, so here it is once.
**	This reduces the code size of MoreFiles.
*/
static pascal	OSErr	GetVolumeInfoNoName(ConstStr255Param pathname,
									short vRefNum,
									HParmBlkPtr pb)
{
	Str255 tempPathname;
	OSErr error;
	
	/* Make sure pb parameter is not NULL */ 
	if ( pb != NULL )
	{
		pb->volumeParam.ioVRefNum = vRefNum;
		if ( pathname == NULL )
		{
			pb->volumeParam.ioNamePtr = NULL;
			pb->volumeParam.ioVolIndex = 0;		/* use ioVRefNum only */
		}
		else
		{
			BlockMoveData(pathname, tempPathname, pathname[0] + 1);	/* make a copy of the string and */
			pb->volumeParam.ioNamePtr = (StringPtr)tempPathname;	/* use the copy so original isn't trashed */
			pb->volumeParam.ioVolIndex = -1;	/* use ioNamePtr/ioVRefNum combination */
		}
		error = PBHGetVInfoSync(pb);
		pb->volumeParam.ioNamePtr = NULL;	/* ioNamePtr may point to local	tempPathname, so don't return it */
	}
	else
	{
		error = paramErr;
	}
	return ( error );
}
int __PHYSFS_platformClose(void *opaque)
{
    SInt16 ref = *((SInt16 *) opaque);
    SInt16 vRefNum;
    Str63 volName;
    int flushVol = 0;

    if (GetVRefNum(ref, &vRefNum) == noErr)
    {
        HParamBlockRec hpbr;
        memset(&hpbr, '\0', sizeof (HParamBlockRec));
        hpbr.volumeParam.ioNamePtr = volName;
        hpbr.volumeParam.ioVRefNum = vRefNum;
        hpbr.volumeParam.ioVolIndex = 0;
        if (PBHGetVInfoSync(&hpbr) == noErr)
            flushVol = 1;
    } /* if */

    BAIL_IF_MACRO(oserr(FSClose(ref)) != noErr, NULL, 0);
    free(opaque);

    if (flushVol)
        FlushVol(volName, vRefNum);  /* update catalog info, etc. */

    return(1);
} /* __PHYSFS_platformClose */
Exemple #3
0
/* フルパスからボリューム番号とディレクトリIDを取得する */
static OSErr PathToSpec(const char *pathname, short *vRefNum, long *dirID,
			Boolean *is_dir)
{
  FSSpec spec;
  OSErr  err;
  UInt8  temp[257];
  int    i;
  CInfoPBRec pbr;
  HParamBlockRec hpbr;

  if( is_dir ) *is_dir = FALSE;

  temp[0] = strlen(pathname);
  strcpy((char*)&temp[1], pathname);
  if (!strchr(pathname, ':')) {		/* : が含まれない場合 (ボリューム?) */
    hpbr.volumeParam.ioNamePtr = temp;
    i = 1;
    do {
      hpbr.volumeParam.ioVolIndex = i;
      err = PBHGetVInfoSync(&hpbr);
      temp[temp[0] + 1] = 0;
      if (err == noErr && !strcmp((char*)&temp[1], pathname)) {
        *vRefNum = hpbr.volumeParam.ioVRefNum;
        *dirID   = fsRtDirID;
	if( is_dir ) *is_dir = TRUE;
        return err;
      }
      i++;
    } while (err == noErr);
    return err;
  }

  err = FSMakeFSSpec(-1, 1, temp, &spec);
  if (err != noErr) return err;

  /* dirIDを取得する */
  pbr.hFileInfo.ioNamePtr = spec.name;
  pbr.hFileInfo.ioVRefNum = spec.vRefNum;
  pbr.hFileInfo.ioFDirIndex = 0;
  pbr.hFileInfo.ioDirID     = spec.parID;
  pbr.hFileInfo.ioACUser    = 0;
  err = PBGetCatInfoSync(&pbr);
  if (err == noErr ){
    *vRefNum = pbr.hFileInfo.ioVRefNum;
    *dirID   = pbr.hFileInfo.ioDirID;
    if (pbr.hFileInfo.ioFlAttrib & 16) {
      if( is_dir ) *is_dir = TRUE;
    }
    return noErr;
  }
  return err;
}
Exemple #4
0
/* Eject the CD-ROM */
static int SDL_SYS_CDEject(SDL_CD *cdrom)
{
	Boolean	disk = false;
	QHdr *driveQ = GetDrvQHdr();
	DrvQEl *driveElem;
	HParamBlockRec hpb;
	ParamBlockRec cpb;

	for ( driveElem = (DrvQEl *) driveQ->qHead; driveElem; driveElem = 
			  (driveElem) ? ((DrvQEl *) driveElem->qLink) : 
			  ((DrvQEl *) driveQ->qHead) ) {
		if ( driveQ->qTail ) {
			driveQ->qTail->qLink = 0;
		}
		if ( driveElem->dQRefNum != SDL_cdlist[cdrom->id].dRefNum ) {
			continue;
		}
	
		/* Does drive contain mounted volume? If not, skip */
		SDL_memset(&hpb, 0, sizeof(hpb));
		hpb.volumeParam.ioVRefNum = driveElem->dQDrive;
		if ( PBHGetVInfoSync(&hpb) != noErr ) {
			continue;
		}
		if ( (UnmountVol(0, driveElem->dQDrive) == noErr) && 
		     (Eject(0, driveElem->dQDrive) == noErr) ) {
			driveElem = 0; /* Clear pointer to reset our loop */
			disk = true;
		}
	}

	/* If no disk is present, just eject the tray */
	if (! disk) {
		SDL_memset(&cpb, 0, sizeof(cpb));
		cpb.cntrlParam.ioVRefNum = 0; /* No Drive */
		cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
		cpb.cntrlParam.csCode = kEjectTheDisc;
		if ( PBControlSync((ParmBlkPtr)&cpb) != noErr ) {
			SDL_SetError("PBControlSync() failed");
			return(-1);
		}
	}
	return(0);
}
Exemple #5
0
int
TclpListVolumes( 
		Tcl_Interp *interp)    /* Interpreter to which to pass the volume list */
{
    HParamBlockRec pb;
    Str255 name;
    OSErr theError = noErr;
    Tcl_Obj *resultPtr, *elemPtr;
    short volIndex = 1;

    resultPtr = Tcl_NewObj();
        
    /*
     * We use two facts:
     * 1) The Mac volumes are enumerated by the ioVolIndex parameter of
     * the HParamBlockRec.  They run through the integers contiguously, 
     * starting at 1.  
     * 2) PBHGetVInfoSync returns an error when you ask for a volume index
     * that does not exist.
     * 
     */
        
    while ( 1 ) {
        pb.volumeParam.ioNamePtr = (StringPtr) & name;
        pb.volumeParam.ioVolIndex = volIndex;
                
        theError = PBHGetVInfoSync(&pb);

        if ( theError != noErr ) {
            break;
        }
                
        elemPtr = Tcl_NewStringObj((char *) name + 1, (int) name[0]);
        Tcl_AppendToObj(elemPtr, ":", 1);
        Tcl_ListObjAppendElement(interp, resultPtr, elemPtr);
                
        volIndex++;             
    }
        
    Tcl_SetObjResult(interp, resultPtr);
    return TCL_OK;      
}
Exemple #6
0
void sync( void )
{
	int i = 0;
	
	OSErr err;
	
	do
	{
		HParamBlockRec pb;
		
		pb.volumeParam.ioNamePtr  = NULL;
		pb.volumeParam.ioVRefNum  = 0;
		pb.volumeParam.ioVolIndex = ++i;
		
		err = PBHGetVInfoSync( &pb );
		
		if ( err == noErr )
		{
			err = FlushVol( NULL, pb.volumeParam.ioVRefNum );
		}
	}
	while ( err != nsvErr );
}
boolean filegetdiskicon (short vnum, Handle *hdiskicon) {

	HParamBlockRec pb;
	ParamBlockRec cpb;
	OSErr ec;

	clearbytes (&pb, longsizeof (pb));
    
	pb.volumeParam.ioVRefNum = vnum;
    
	ec = PBHGetVInfoSync (&pb);
    
	if (fileerror (nil, ec))
		return (false);
    	
	cpb.cntrlParam.ioCRefNum = pb.volumeParam.ioVDRefNum;
    
	cpb.cntrlParam.ioVRefNum = pb.volumeParam.ioVDrvInfo;

	cpb.cntrlParam.csCode = 22;
    
	ec = PBControlSync (&cpb);

	if (ec != noErr) {
    
		cpb.cntrlParam.csCode = 21;
        
		ec = PBControlSync (&cpb);
		}
    	
	if (fileerror (nil, ec))
    	return (false);

	ec = PtrToHand (*(Ptr*) &cpb.cntrlParam.csParam, hdiskicon, kLargeIconSize);
	
	return (!fileerror (nil, ec));
	} /*filegetdiskicon*/
Exemple #8
0
DIR *opendir(char *dirName)
{
    int fullPath;
    unsigned pathLen;
    char *s;
    HParamBlockRec hPB;
    CInfoPBRec cPB;
    DIR *dPtr;
    OSErr err;
    FSSpec spec;
    char CompletePath[NAME_MAX];

    GetCompletePath(CompletePath, dirName, &spec, &err);
    printerr("GetCompletePath", err, err, __LINE__, __FILE__, dirName);

    if (dirName == NULL || *dirName == '\0' ||
        (pathLen = strlen(dirName)) >= 256) {
        errno = EINVAL;
        return NULL;
    }


    /* Get information about volume. */
    memset(&hPB, '\0', sizeof(hPB));

    if (((s = strchr(dirName, ':')) == NULL) || (*dirName == ':')) {
        fullPath = false;
    } else {
        *(s + 1) = '\0';
        hPB.volumeParam.ioVolIndex = -1;
        fullPath = true;
    }

    hPB.volumeParam.ioNamePtr = spec.name;

    err = PBHGetVInfoSync(&hPB);

    if ((err != noErr) || (hPB.volumeParam.ioVFSID != 0)) {
        errno = ENOENT;
        return NULL;
    }

    /* Get information about file. */

    memset(&cPB, '\0', sizeof(cPB));

    if (fullPath)
        cPB.hFileInfo.ioVRefNum = hPB.volumeParam.ioVRefNum;

    cPB.hFileInfo.ioNamePtr = spec.name;

    err = PBGetCatInfoSync(&cPB);

    if (err != noErr) {
        errno = (err == fnfErr) ? ENOENT : EIO;
        return NULL;
    }

    if (!(cPB.hFileInfo.ioFlAttrib & ioDirMask)) {
        errno = ENOTDIR;
        return NULL;
    }

    /* Get space for, and fill in, DIR structure. */

    if ((dPtr = (DIR *)malloc(sizeof(DIR))) == NULL) {
        return NULL;
    }

    dPtr->ioVRefNum = cPB.dirInfo.ioVRefNum;
    dPtr->ioDrDirID = cPB.dirInfo.ioDrDirID;
    dPtr->ioFDirIndex = 1;
    dPtr->flags = 0;

    return dPtr;
}
int dir_Lookup(char *pathString, int pathStringLength, int index,
  /* outputs: */
  char *name, int *nameLength, int *creationDate, int *modificationDate,
  int *isDirectory, squeakFileOffsetType *sizeIfFile) {
	/* Lookup the index-th entry of the directory with the given path, starting
	   at the root of the file system. Set the name, name length, creation date,
	   creation time, directory flag, and file size (if the entry is a file).
	   Return:	0 	if a entry is found at the given index
	   			1	if the directory has fewer than index entries
	   			2	if the given path has bad syntax or does not reach a directory
	*/

	int okay;
	HVolumeParam volumeParams;
    FSSpec      spec;
    long        parentDirectory;
    OSErr       err;
    Str255      longFileName;
    
	/* default return values */
	*name             = 0;
	*nameLength       = 0;
	*creationDate     = 0;
	*modificationDate = 0;
	*isDirectory      = false;
	*sizeIfFile       = 0;

	if ((pathStringLength == 0)) {
		/* get volume info */
		volumeParams.ioNamePtr = (unsigned char *) name;
		volumeParams.ioVRefNum = 0;
		volumeParams.ioVolIndex = index;
		okay = PBHGetVInfoSync((HParmBlkPtr) &volumeParams) == noErr;
		if (okay) {
			CopyPascalStringToC((ConstStr255Param) name,name);
			*nameLength       = strlen(name);
			*creationDate     = convertToSqueakTime(volumeParams.ioVCrDate);
			*modificationDate = convertToSqueakTime(volumeParams.ioVLsMod);
			*isDirectory      = true;
			*sizeIfFile       = 0;
			return ENTRY_FOUND;
		} else {
			return NO_MORE_ENTRIES;
		}
	} else {
		/* get file or directory info */
		if (!equalsLastPath(pathString, pathStringLength)) {
 			/* lookup and cache the refNum for this path */
			err = lookupPath(pathString, pathStringLength, &spec,false,true);
 			if (err == noErr) 
				recordPath(pathString, pathStringLength, &spec);
			else 
				return BAD_PATH;
		}
	    spec = lastSpec;
				*sizeIfFile   = 0;
		okay = fetchFileInfo(index,&spec,(unsigned char *) name,true,&parentDirectory,isDirectory,creationDate,modificationDate,sizeIfFile,&longFileName);
		if (okay == noErr) {
			CopyPascalStringToC((ConstStr255Param) longFileName,name);
			*nameLength       = strlen(name);
			*creationDate     = convertToSqueakTime(*creationDate);
			*modificationDate = convertToSqueakTime(*modificationDate);
			return ENTRY_FOUND;
		} else
			return okay == fnfErr ? NO_MORE_ENTRIES : BAD_PATH;
	}
}
Exemple #10
0
/*---------------------------------------------------------------------------
 * トップレベル (ボリュームの一覧)
 *---------------------------------------------------------------------------*/
static	T_DIR_INFO	*openroot(void)
{
  char *p;
  short	 i;
  OSErr  err;
  int    num;
  T_DIR_INFO	*dir;
  Str63		temp;
  HParamBlockRec pbr;

				/* T_DIR_INFO ワークを 1個確保 */
  if( (dir = (T_DIR_INFO *)malloc( sizeof(T_DIR_INFO) ))==NULL ){
    return NULL;
  }

  /* 項目の数を取得する */
  dir->nr_entry = 0;
  i = 1;
  pbr.volumeParam.ioNamePtr = temp;
  do {
    pbr.volumeParam.ioVolIndex = i;
    err = PBHGetVInfoSync(&pbr);
    if (err == noErr) {
      dir->nr_entry += 1;
    }
    i++;
  } while (err == noErr);

  if( dir->nr_entry==0 ){
    free( dir );
    return NULL;
  }
				/* T_DIR_ENTRY ワークを 項目数分 確保 */
  dir->entry = (T_DIR_ENTRY *)malloc( dir->nr_entry * sizeof(T_DIR_ENTRY) );
  if( dir->entry==NULL ){
    free( dir );
    return NULL;
  }
  for( i=0; i<dir->nr_entry; i++ ) {
    dir->entry[ i ].name = NULL;
  /*dir->entry[ i ].str  = NULL;*/
  }


  dir->cur_entry = 0;

  /* フォルダ内の項目を追加 */
  i = 1;
  num = 0;
  pbr.volumeParam.ioNamePtr = temp;
  do {
    pbr.volumeParam.ioVolIndex = i;
    err = PBHGetVInfoSync(&pbr);
    if (err == noErr) {
      temp[temp[0] + 1] = 0;

      p = (char *)malloc( (temp[0] + 1) + (temp[0] + 1) );
      if( p==NULL ){	/* ↑ファイル名    ↑表示名    */
	dir->nr_entry = num;
        break;
      }

      dir->entry[ num ].name = &p[0];
      dir->entry[ num ].str =  &p[(temp[0] + 1)];

      strcpy(dir->entry[ num ].name, (char*)&temp[1]);	/* ファイル名 */
      strcpy(dir->entry[ num ].str,  (char*)&temp[1]);	/* 表示名     */

      dir->entry[ num ].type = FILE_STAT_DIR;
      num++;
    }
    i++;
  } while (err == noErr && num < dir->nr_entry);

  dir->nr_entry = num;

  return dir;
}
int Zmacstat(const char *Fname, struct stat *buf)
{
    OSErr           err, rc;
    short           fullPathLength;
    Handle          hFullPath;
    char            path[NAME_MAX], path2[NAME_MAX];
    HVolumeParam    vpb;
    static unsigned long count_of_files = 0;

    AssertStr(Fname,Fname)
    Assert_it(buf,"","")

    UserStop();

    memset(buf, 0, sizeof(buf));    /* zero out all fields */

    RfDfFilen2Real(path2, Fname, MacZip.MacZipMode, MacZip.DataForkOnly,
                   &MacZip.CurrentFork);
    GetCompletePath(path, path2, &MacZip.fileSpec, &err);
    err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
    printerr("GetCompletePath:", err, err, __LINE__, __FILE__, path);

    if (err != noErr) {
        errno = err;
        return -1;
    }

    /*  Collect here some more information, it's not related to Macstat.
        (note: filespec gets changed later in this function) */
    /* clear string-buffer */
    memset(MacZip.FullPath, 0x00, sizeof(MacZip.FullPath));
    rc = FSpGetFullPath(&MacZip.fileSpec, &fullPathLength, &hFullPath);
    strncpy(MacZip.FullPath, *hFullPath, fullPathLength);
    DisposeHandle(hFullPath);   /* we don't need it any more */
    /*  Collect some more information not related to Macstat */


    /*
     * Fill the fpb & vpb struct up with info about file or directory.
     */

    FSpGetDirectoryID(&MacZip.fileSpec, &MacZip.dirID, &MacZip.isDirectory);
    vpb.ioVRefNum = MacZip.fpb.hFileInfo.ioVRefNum =  MacZip.fileSpec.vRefNum;
    vpb.ioNamePtr = MacZip.fpb.hFileInfo.ioNamePtr =  MacZip.fileSpec.name;

    if (MacZip.isDirectory) {
        MacZip.fpb.hFileInfo.ioDirID =  MacZip.fileSpec.parID;
        /*
         * Directories are executable by everyone.
         */
        buf->st_mode |= UNX_IXUSR | UNX_IXGRP | UNX_IXOTH | UNX_IFDIR;
    } else {
        MacZip.fpb.hFileInfo.ioDirID = MacZip.dirID;
    }

    MacZip.fpb.hFileInfo.ioFDirIndex = 0;
    err = PBGetCatInfoSync((CInfoPBPtr)&MacZip.fpb);

    if (err == noErr) {
        vpb.ioVolIndex = 0;
        err = PBHGetVInfoSync((HParmBlkPtr)&vpb);
        if (err == noErr && buf != NULL) {
            /*
             * Files are always readable by everyone.
             */
            buf->st_mode |= UNX_IRUSR | UNX_IRGRP | UNX_IROTH;

            /*
             * Use the Volume Info & File Info to fill out stat buf.
             */
            if (MacZip.fpb.hFileInfo.ioFlAttrib & 0x10) {
                buf->st_mode |= UNX_IFDIR;
                buf->st_nlink = 2;
            } else {
                buf->st_nlink = 1;
                if (MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags & 0x8000) {
                    buf->st_mode |= UNX_IFLNK;
                } else {
                    buf->st_mode |= UNX_IFREG;
                }
            }

            if (MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType == 'APPL') {
                /*
                 * Applications are executable by everyone.
                 */
                buf->st_mode |= UNX_IXUSR | UNX_IXGRP | UNX_IXOTH;
            }
            if ((MacZip.fpb.hFileInfo.ioFlAttrib & 0x01) == 0){
                /*
                 * If not locked, then everyone has write acces.
                 */
                buf->st_mode |= UNX_IWUSR | UNX_IWGRP | UNX_IWOTH;
            }

            buf->st_ino = MacZip.fpb.hFileInfo.ioDirID;
            buf->st_dev = MacZip.fpb.hFileInfo.ioVRefNum;
            buf->st_uid = -1;
            buf->st_gid = -1;
            buf->st_rdev = 0;

            if (MacZip.CurrentFork == ResourceFork)
                buf->st_size = MacZip.fpb.hFileInfo.ioFlRLgLen;
            else
                buf->st_size = MacZip.fpb.hFileInfo.ioFlLgLen;

            buf->st_blksize = vpb.ioVAlBlkSiz;
            buf->st_blocks = (buf->st_size + buf->st_blksize - 1)
                            / buf->st_blksize;

            /*
             * The times returned by the Mac file system are in the
             * local time zone.  We convert them to GMT so that the
             * epoch starts from GMT.  This is also consistent with
             * what is returned from "clock seconds".
             */
            if (!MacZip.isDirectory) {
                MacZip.CreatDate  = MacZip.fpb.hFileInfo.ioFlCrDat;
                MacZip.ModDate    = MacZip.fpb.hFileInfo.ioFlMdDat;
                MacZip.BackDate   = MacZip.fpb.hFileInfo.ioFlBkDat;
            } else {
                MacZip.CreatDate  = MacZip.fpb.dirInfo.ioDrCrDat;
                MacZip.ModDate    = MacZip.fpb.dirInfo.ioDrMdDat;
                MacZip.BackDate   = MacZip.fpb.dirInfo.ioDrBkDat;
            }

#ifdef IZ_CHECK_TZ
            if (!zp_tz_is_valid)
            {
                MacZip.HaveGMToffset = false;
                MacZip.Md_UTCoffs = 0L;
                MacZip.Cr_UTCoffs = 0L;
                MacZip.Bk_UTCoffs = 0L;
            }
            else
#endif
            {
                /* Do not use GMT offsets when Md_UTCoffs calculation
                 * fails, since this time stamp is used for time
                 * comparisons in Zip and UnZip operations.
                 * We do not bother when GMT offset calculation fails for
                 * any other time stamp value. Instead we simply assume
                 * a default value of 0.
                 */
                MacZip.HaveGMToffset =
                    GetGMToffsetMac(MacZip.ModDate, &MacZip.Md_UTCoffs);
                if (MacZip.HaveGMToffset) {
                    GetGMToffsetMac(MacZip.CreatDate, &MacZip.Cr_UTCoffs);
                    GetGMToffsetMac(MacZip.BackDate, &MacZip.Bk_UTCoffs);
                } else {
                    MacZip.Cr_UTCoffs = 0L;
                    MacZip.Bk_UTCoffs = 0L;
                }
            }
#ifdef DEBUG_TIME
            {
            printf("\nZmacstat:  MacZip.HaveGMToffset: %d",
               MacZip.HaveGMToffset);
            printf("\nZmacstat:  Mac modif: %lu local -> UTOffset: %d",
              MacZip.ModDate, MacZip.Md_UTCoffs);
            printf("\nZmacstat:  Mac creat: %lu local -> UTOffset: %d",
              MacZip.CreatDate, MacZip.Cr_UTCoffs);
            printf("\nZmacstat:  Mac  back: %lu local -> UTOffset: %d",
              MacZip.BackDate, MacZip.Bk_UTCoffs);
            }
#endif /* DEBUG_TIME */


            buf->st_mtime = MacFtime2UnixFtime(MacZip.ModDate);
            buf->st_ctime = MacFtime2UnixFtime(MacZip.CreatDate);
            buf->st_atime = buf->st_mtime;

#ifdef DEBUG_TIME
            {
            printf("\nZmacstat:  Unix modif: %lu UTC; Mac: %lu local",
              buf->st_mtime, MacZip.ModDate);
            printf("\nZmacstat:  Unix creat: %lu UTC; Mac: %lu local\n",
              buf->st_ctime, MacZip.CreatDate);
            }
#endif /* DEBUG_TIME */

            if (noisy)
            {
                if (MacZip.StatingProgress)
                {
                    count_of_files++;
                    InformProgress(MacZip.RawCountOfItems, count_of_files );
                }
                else
                    count_of_files = 0;
            }
        }
    }

    if (err != noErr) {
        errno = err;
    }

    MacZip.isMacStatValid = true;
    return (err == noErr ? 0 : -1);
}