pfsfreeblocks.c 1.86 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
osPfsFreeBlocks(OSPfs *pfs, s32 *bytes_not_used)
{
	int j;
	int pages = 0;
	__OSInode inode;
	s32 ret = 0;
	u8 bank;
#ifdef	_PFS_1M_EXTENSION
	u8 startbank;
#endif
	int offset;

	if (!(pfs->status & PFS_INITIALIZED))
		return(PFS_ERR_INVALID);

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

#ifdef	_PFS_1M_EXTENSION
	if (pfs->banks < PFS_ID_BANK_1M) {
	  startbank = PFS_ID_BANK_256K;
	} else {
	  startbank = PFS_ID_BANK_1M;
	}
	for (bank = startbank; bank < pfs->banks; bank++) {
#else
	for (bank = PFS_ID_BANK_256K; bank < pfs->banks; bank++) {
#endif
		if ((ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank)) != 0)
			return(ret);

#ifdef	_PFS_1M_EXTENSION
		offset = ((bank > PFS_ID_BANK_1M) ? 1 : pfs->inode_start_page);
#else
		offset = ((bank > PFS_ID_BANK_256K) ? 1 : pfs->inode_start_page);
#endif
		for (j = offset ; j <PFS_INODE_SIZE_PER_PAGE; j++) {
			if (inode.inode_page[j].ipage == PFS_PAGE_NOT_USED)
			  pages++;
		}
	}

	*bytes_not_used = (s32)(pages * PFS_ONE_PAGE * BLOCKSIZE);
	return(0);
}