fsdir.c 788 Bytes
#include <PR/bcp.h>
#include "os.h"
#include "os_bbfs.h"
#include "bbint.h"
s32
osBbFReadDir(OSBbDirEnt* dir, u32 count) {
    s32 rv, i, j;
     BbInode* in;
     BbFat16* fat;
     OSBbDirEnt* d = dir;
    if ((rv = __osBbFsGetAccess()) < 0) return rv;
    fat = __osBbFat;
    for(j = i = 0; i < BB_INODE16_ENTRIES; i++) {
	s32 k;
	if (!(in = fat->inode+i)->type) continue;
	rv++;
	if (!d || j >= count) continue;
	d->type = in->type;
	d->size = in->size;
	for(k = 0; in->name[k] && k < BB_INODE16_NAMELEN-3; k++)
	    d->name[k] = in->name[k];
	if (in->name[BB_INODE16_NAMELEN-3]) {
	    d->name[k] = '.';
	    bcopy(in->name+BB_INODE16_NAMELEN-3, d->name+k+1, 3);
	    d->name[k+1+3] = '\0';
	} else
	    d->name[k] = '\0';
	d++; j++;
    }
    __osBbFsRelAccess();
    return rv;
}