pfsfreeblocks.c
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**************************************************************************
* *
* 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);
}