fsstat.c 808 Bytes
#include <PR/bcp.h>
#include "os.h"
#include "os_bbfs.h"
#include "bbint.h"
s32
osBbFStat(s32 fd, OSBbStatBuf* sb, u16* blockList, u32 listLen) {
    int i;
    s32 rv = BBFS_ERR_INVALID;
    BbInode* in;
    BbFat16* fat;
    if (fd < 0 || fd >= BB_INODE16_ENTRIES) return rv;
    if ((rv = __osBbFsGetAccess()) < 0) return rv;
    fat = __osBbFat;
    in = fat->inode+fd;
    /* check size, etc */
    rv = BBFS_ERR_INVALID;
    if (!in->type) goto error;
    sb->type = in->type;
    sb->size = in->size;
    if (blockList && listLen) {
	u16 b;
	/* retrieve block list */
	b = in->block;
	for(i = 0; b != BB_FAT_LAST && i < listLen; i++) {
	    blockList[i] = b;
	    b = BB_FAT16_NEXT(fat,b);
	}
	if (i < listLen)
	    blockList[i] = 0;
    }
    rv = 0;
error:
    __osBbFsRelAccess();
    return rv;
}