pfsfilestate.c 2.65 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
osPfsFileState(OSPfs *pfs, s32 file_no, OSPfsState *state)
{
	s32 ret;
	int pages;
	__OSInode inode;
	__OSDir dir;
	__OSInodeUnit next_page;
	u8 bank;

	/* 
	 * typedef struct {
	 *	u32     file_size;
	 *	u32     game_code;
	 *	u16     company_code;
	 *	char    ext_name[4];
	 *	char    game_name[16];
	 * } OSPfsState;
	 */
	

	/* Check valid ID and parameters */

	if ((file_no >= (s32)pfs->dir_size) || (file_no < 0))
		return(PFS_ERR_INVALID);
	if (!(pfs->status & PFS_INITIALIZED))
		return(PFS_ERR_INVALID);

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

	/* get dir and inode structures */

#ifdef	_PFS_1M_EXTENSION
	if ((ret = __osPfsSelectIdBank(pfs)) != 0) return(ret);
#else
	if (pfs->activebank != 0)
	  if ((ret = __osPfsSelectBank(pfs, 0)) != 0) return(ret);
#endif

	if ((ret = __osContRamRead(pfs->queue, pfs->channel,
                (u16)(pfs->dir_table + (int)file_no), (u8 *)&dir)) != 0)
                return(ret);
	if ((dir.company_code == 0) || (dir.game_code == 0))
		return(PFS_ERR_INVALID);
	
	/* get file status and calculate file size */
	pages = 0;
	next_page = dir.start_page;
	bank = 255;
	while(1) {
	  if (next_page.ipage < pfs->inode_start_page) {
	    break;
	  } else if (next_page.inode_t.bank != bank) {
	    bank = next_page.inode_t.bank;
	    if ((ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank)) != 0)
	      return(ret);
	  }
	  pages++;
	  next_page = inode.inode_page[next_page.inode_t.page];
	}

	if (next_page.ipage != PFS_EOF)
		return(PFS_ERR_INCONSISTENT);
	state->file_size = (u32)(pages * PFS_PAGE_SIZE);
	state->company_code = dir.company_code;
	state->game_code = dir.game_code;
	bcopy(dir.game_name, state->game_name, PFS_FILE_NAME_LEN);
	bcopy(dir.ext_name, state->ext_name, PFS_FILE_EXT_LEN);

	ret = __osPfsGetStatus(pfs->queue, pfs->channel);
	return(ret);
}