pfssearchfile.c 1.93 KB

/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1995, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright law.  They  may  not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 **************************************************************************/

#include "osint.h"
#include "controller.h"

s32
osPfsFindFile(OSPfs *pfs, u16 company_code, u32 game_code, 
		u8 *game_name, u8 *ext_name, s32 *file_no)
{
	s32 j;
	int i;
	__OSDir dir;
	s32 ret = 0;
	int fail;
	
	if (!(pfs->status & PFS_INITIALIZED))
		return(PFS_ERR_INVALID);

	if ((ret=__osCheckId(pfs)) != 0){
		return(ret);
	}

	for (j = 0; j < (s32)pfs->dir_size; j++) {
		if ((ret = __osContRamRead(pfs->queue, pfs->channel,
			(u16)(pfs->dir_table + (int)j), (u8 *)&dir)) != 0)
			return(ret);
		if ((ret = __osPfsGetStatus(pfs->queue, pfs->channel)) != 0){
		  return(ret);
		}

		if ((dir.company_code == company_code) && 
					(dir.game_code == game_code)) {
			fail = 0;
			if (game_name != 0) {
				for(i = 0 ; i < PFS_FILE_NAME_LEN ; i++)
					if (dir.game_name[i] != game_name[i]) {
						fail = 1;
						break;
					}
			}
			if ((ext_name != 0) && (fail == 0)){
				for(i = 0 ; i < PFS_FILE_EXT_LEN ; i++)
					if (dir.ext_name[i] != ext_name[i]){
						fail = 1;
						break;
					}
			}
			if (fail == 0) {
				*file_no = j;
				return(ret);
			}
		}
	}
	*file_no = -1;
	return(PFS_ERR_INVALID);	/* file not found */
}