pfsreformat.c 3.32 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"
#include "siint.h"

/* 
 * This function reformat the whole file system except pack id
 * which is assigned by Nintendo.
 */
s32 
osPfsReFormat(OSPfs *pfs, OSMesgQueue *queue, int channel)
{
  int j, i;
  __OSInode inode;
  u8 tmp_data[BLOCKSIZE];
  u8 *ptr;
  s32 ret;

  /* Block to get resource token */
        __osSiGetAccess();

  if ((ret = __osPfsGetStatus(queue, channel)) != 0) {
    __osSiRelAccess();
    return(ret);
  }
  
  pfs->status ^= PFS_INITIALIZED;
  pfs->queue = queue;
  pfs->channel = channel;
	/* Check vaild id */

  __osSiRelAccess();
  if ((ret = __osGetId(pfs)) != 0)
	return(ret);

#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

  /* make dir */
  for(j = 0; j < BLOCKSIZE ; j++) 
	tmp_data[j] = 0;
  for(j = 0; j < pfs->dir_size ; j++) {
	  ret = __osContRamWrite(queue, channel, (u16)(pfs->dir_table+j), 
				tmp_data, 0);
	  if (ret != 0)
		return(ret);
  }

  /* make inode table for bank 0 */
  for(j = 0 ; j < pfs->inode_start_page ; j++)
	  inode.inode_page[j].ipage = 0;
	
  for(j = pfs->inode_start_page ; j < PFS_INODE_SIZE_PER_PAGE; j++)
	  inode.inode_page[j].ipage = PFS_PAGE_NOT_USED;

  inode.inode_page[0].ipage = (u16)__osSumcalc((u8 *)(inode.inode_page + 
    pfs->inode_start_page),(PFS_INODE_SIZE_PER_PAGE -pfs->inode_start_page)*2 );
  ptr = (u8 *)(&inode);
		
  for(j = 0; j < PFS_ONE_PAGE ; j++) {
	  ret =__osContRamWrite(queue, channel, 
		(u16)(pfs->inode_table+j), (u8 *)(ptr + (j * BLOCKSIZE)), 0);
	  if (ret != 0)
		return(ret);
	  ret =__osContRamWrite(queue, channel, 
		(u16)(pfs->minode_table+j), (u8 *)(ptr + (j * BLOCKSIZE)), 0);
	  if (ret != 0)
		return(ret);
  }

  /* make inode table for bank 1 to bank n */

  for (i = 1; i < pfs->banks; i++) {
	  for(j = 1 ; j < PFS_INODE_SIZE_PER_PAGE; j++)
		  inode.inode_page[j].ipage = PFS_PAGE_NOT_USED;

	  inode.inode_page[0].ipage = 
				(u16)__osSumcalc((u8 *)(inode.inode_page + 1), 
				(PFS_INODE_SIZE_PER_PAGE - 1) * 2);
	  ptr = (u8 *)(&inode);
			
	  for(j = 0; j < PFS_ONE_PAGE ; j++) {
		  ret =__osContRamWrite(queue, channel, 
			(u16)(pfs->inode_table + (i * PFS_ONE_PAGE) +j), 
			(u8 *)(ptr + (j * BLOCKSIZE)), 0);
		  if (ret != 0)
			return(ret);
		  ret =__osContRamWrite(queue, channel, 
			(u16)(pfs->minode_table + (i * PFS_ONE_PAGE) +j), 
			(u8 *)(ptr + (j * BLOCKSIZE)), 0);
		  if (ret != 0)
			return(ret);
	  }
  }

  return(0);
}